locked
Memory management with single page Navigation RRS feed

  • Question

  • Hello guys,

    I'm having a little issue with the memory management in my app. I'm using the WinJS Navigation Controls to navigate (similar to the way used in the Split Application Template). The issue I'm having is that when a page is loaded, it seems to never be removed from the memory.

    I understand that the Navigator keeps the Pages in the BackStack alive (or atleast saves the element Tree in some manner) in order to be able to go back without having to reload and that's fine, however I would like these pages to be removed from memory once I have navigated back and the page is basically no longer needed.

    Just a quick example to show you what I mean:
    Navigate to detailpage ->
    detailpage navigates to detailpage(with new item) ->
    User navigates back and is now on the first detailPage. At this point the second detailpage should be unloaded from the memory.

    How can I accomplish this?

    Just as a side note, I have looked at a similarly structured app (Dailymotion) and it seems to be suffering a similar issue, with the memory footprint steadily growing with ongoing use.

    Thanks very much for any help!

    Happy Coding,

    Censored

    Sunday, April 1, 2012 5:56 PM

Answers

  • Hi Censored - what's happening is that the garbage collection engine in Chakra (running IE and WWAs) is really slow to start GC.  If I force a GC, the memory used by the WWAHost drops down, indicating that this is not a memory leak - a leak would not release the objects in memory if they were referenced.

    You can see this for yourself - create the split template project as you described above, then add a link to a new page in default.html page:

    <a href="gcpage.html">Go to Garbage Collection Page</a>

    Here's the code for gcpage.html:

    <!DOCTYPE html>
    <html>
        <head>
            <meta http-equiv="X-UA-Compatible" content="IE=10" />
            <title>Force Garbage Collection</title>
        </head>
        <script type="text/javascript">
            for (var i = 0; i < 5; i++) {
                CollectGarbage();
            }
        </script>
        <body>
            <div>
                Garbage Collection Page
            </div>
        </body>
    </html>
    
    When you're ready to see used memory drop, just navigate to this page.




    Matt Small - Microsoft Escalation Engineer - Forum Moderator

    Monday, April 16, 2012 2:37 PM
    Moderator

All replies

  • Hi Censored - I'll look for bugs on this and see if I can repro it if no bugs show up.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator

    Wednesday, April 4, 2012 3:19 PM
    Moderator
  • OK, I didn't quite understand your post previously.  My question for you is:  when you navigate back to the first detailpage, and then go to a third detailpage, does the memory footprint decrease, either immediately, or over time?  If you consistently and quickly load a new page, does the memory increase forever, or does it eventually compact? 

    Also, how does the lack of memory management affect you?  Are you loading so many pages that you are actually consuming a lot of memory (more than 1Gb?) or are you just thinking that you might eventually do so?


    Matt Small - Microsoft Escalation Engineer - Forum Moderator

    Wednesday, April 4, 2012 7:16 PM
    Moderator
  • Hi Matt,

    when I navigate back to the first detailpage the memory footprint increases (weirdly enough) and when I then navigate to another (third) it increases again. The overall footprint never seems to decrease.

    If i just click through pages quickly for around 2 minutes the memory footprint can easily rise to over 500Mb and I think if i kept going it would reach over 1Gb too.
    Obviously I'm having some sort of memory leak issue here, as the only way to free the memory seems to be closing the app.

    I'm not really sure what to look for and as far as I know there is no way to see what is actually using the memory (is there?).


    EDIT: Okay I just tried to reproduce the issue in a new project (Split Application template) and it seems to happen there too.

    Here is what I did:

    1. Create new Split Application project. 

    2. Add large Background image to the default.css

    .fragment {background-image: url(/images/background.png);}

    3. Run project and click Group 1 and then back repeatedly. (Click backspace spamming)

    4. Watch memory rise and never decrease.

    Thursday, April 5, 2012 12:08 AM
  • Can anyone confirm this as a Problem? Is it being worked on or is it something we will have to deal with?

    Thanks

    Friday, April 13, 2012 11:55 AM
  • Hi - it's an item on my list to get to... this isn't blocking you at this time, is it? 

    Matt Small - Microsoft Escalation Engineer - Forum Moderator

    Friday, April 13, 2012 1:16 PM
    Moderator
  • Hi Censored - what's happening is that the garbage collection engine in Chakra (running IE and WWAs) is really slow to start GC.  If I force a GC, the memory used by the WWAHost drops down, indicating that this is not a memory leak - a leak would not release the objects in memory if they were referenced.

    You can see this for yourself - create the split template project as you described above, then add a link to a new page in default.html page:

    <a href="gcpage.html">Go to Garbage Collection Page</a>

    Here's the code for gcpage.html:

    <!DOCTYPE html>
    <html>
        <head>
            <meta http-equiv="X-UA-Compatible" content="IE=10" />
            <title>Force Garbage Collection</title>
        </head>
        <script type="text/javascript">
            for (var i = 0; i < 5; i++) {
                CollectGarbage();
            }
        </script>
        <body>
            <div>
                Garbage Collection Page
            </div>
        </body>
    </html>
    
    When you're ready to see used memory drop, just navigate to this page.




    Matt Small - Microsoft Escalation Engineer - Forum Moderator

    Monday, April 16, 2012 2:37 PM
    Moderator
  • I have been facing a similar issue with the c# metro app. Between page navigations, memory utilized keeps increasing and never seems to fall down. Inspite of explicitly setting objects to NULL so as to force GC, there seems to be no effect on the utilized app memory. Anything specific related to the metro app cycle?

    Tuesday, October 16, 2012 8:24 AM
  • Hi Matt Small, I have the same problem, the memory keeps increasing and crashs.

    Do you have some solution ? 

    Tuesday, October 23, 2012 12:08 PM