locked
Mem Leak when consuming WinRT Component in JS RRS feed

  • General discussion

  • I set up a pretty simple solution which contains a WinRT Component DLL project and a JavaScript Metro project.
    I use ref new to create a bunch of Calendar objects and return them within a container (IVector) in JS every 5 seconds.
    And I observed linear mem usage increasing during the course.
    Is this usage correct? Why the 'ref new' allocated objects are not released(seems so) in JS? 

    Below are my codes:
    C++

    namespace WinRTComponent
    {
    	public ref class WinRTComponent1 sealed
    	{
    	public:
    		WinRTComponent1();
    
    		IVector<Calendar^>^ Consume()
    		{
    			IVector<Calendar ^>^ cals = ref new Platform::Collections::Vector<Calendar ^>();
    
    			for(unsigned int i = 0; i < 10 * 1024;i ++){
    
    				Calendar^ cal = ref new Calendar();
    				cal->ChangeClock(ClockIdentifiers::TwentyFourHour); // enabling 24 hour format
    				cal->Year = 2012;
    				cal->Month = 5;
    				cal->Day = 2;
    				cal->Hour = 13;
    				cal->Minute = 51;
    				cal->Second = i % 59;
    
    				cals->Append(cal);
    			}
    
    			return cals;
    		}
    	};
    }
    JavaScript:
        function testConsume() {
            setInterval(function () {
                var comp = new WinRTComponent.WinRTComponent1();
                var cals = comp.consume();
                
                // manual release  
                //var len = cals.length;
                //for (var i = 0; i < len; i++) {
                //    var c = cals.getAt(i);
                //    c = null;
                //}
    
                //cals.clear();
                //cals = null;
            }, 5000);



    • Edited by wqter Thursday, May 3, 2012 2:11 AM
    Thursday, May 3, 2012 2:10 AM

All replies

  • Any idea?
    Monday, May 7, 2012 6:32 AM
  • Over time is the memory released (when the JS garbage collection had time to run)?

    Jeff Sanders (MSFT)

    Monday, May 7, 2012 2:12 PM
    Moderator
  • We collected the mem usage at a 1 hour span and the curve keeps growing linearly.
    If we explictly release the passed objects in JS, we can see the curve went up and down like waves.
    We observed similiar behavior in C# (consuming WinRT C++ component)...
    Tuesday, May 8, 2012 12:45 AM
  • Hi W,

    Can you post your C++ component code (or a real simple repro)?

    -Jeff


    Jeff Sanders (MSFT)

    Thursday, May 10, 2012 3:20 PM
    Moderator
  • Hi Jeff

    The code posted at the top is taken from the real project.
    The WinRT C++ Comp code is complete. And the JS code is partial.

    Thursday, May 10, 2012 4:08 PM
  • Nope, it will not build without IVector and Calendar defined.  Can you post your include files?

    Jeff Sanders (MSFT)

    Thursday, May 10, 2012 5:26 PM
    Moderator
  • Partially related: I have a similar issue with my C++ application. I'm almost exclusively using reference classes, and yet I see rising memory usage. Most curiously, when I exclude most of the functionality, leaving the one in that does mallocs, the memory is steady. Does WinRT collect dereferenced objects for bulk removal similar to a GC?
    Friday, May 11, 2012 11:34 PM