locked
How to clear page memory immediately?

    Question

  • Hi All,

    I am developing Shared Store Application. I am seeing the memory size gets increased when navigating from one page to another page, and that memory is not re-collected by GC.

    I have 2 pages, navigating to Page1 to Page2 and back, by doing this, the app memory size gets increased.

    After reading so many articles, I found that, we need to  un-register events that we used in page. and clear the objects. So I have implemented IDisposable interface and un-registered each and every events(not in xaml), and cleared used objects. and calling GC.Collect(), GC.WaitForPendingFinalizers().

    Then OnNavigatedFrom, I am calling Dispose method.

    Now I have observed, The page is destroying when the second instance of the same page is need to clear from memory.

    So when I navigated to Page1->Page2-(back)>Page1->Page2. Now the Page1 destructor is called. I don't understood which instance destructor called. 

    Finally I want to clear the page instance immediately from memory when I navigated to Page2.

    Page1->Page2 then clear Page1 from memory.

    Page2-(back)-> then clear Page2 from memory.

    Thanks in advance


    Pallam Madhukar Windows Phone Developer

    Wednesday, January 21, 2015 6:02 PM

All replies

  • Hi Pallam Madhukar,

    Any reason why do you want to control the page life cycle of the app? You do not have enough memory space while running the app?

    Basically the app will automatically release the page if you do not set Page.CacheMode, and we cannot control when this collect action will start because system control it.

    --James


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, January 22, 2015 3:28 AM
    Moderator
  • Hi Jamles,

    Thank you for replying. My problem is I want recollect all memory when I am navigated back.

    I have Page 1 with one button to navigate to page 2. In page 2 I am displaying photo thumbnails.

    When I started app, memory is between 10-15MB, and when I navigated to Page 2 it become 40-50 MB. and When I navigated back from Page 2. Memory size is 35-45 MB.

    I want to clear all 30-35MB memory, when I navigated back to first page.

    Please advice me.

    Thanks


    Pallam Madhukar Windows Phone Developer


    Friday, January 23, 2015 8:35 AM