locked
[UWP][C#] Do pages stay in memory forever? RRS feed

  • Question

  • A page has a back button, when it is clicked, the following happens:

    Frame.GoBack();
     

    OnNavigatingFrom() is invoked and the page exits properly.  However, the memory snapshot shows this page stays in the memory. If the app enters and exits the page 10 times, there will be 10 instances of this page in the memory snapshot.

    I am wondering if this is related to this SO post.  I observed this when investigating another memory leak problem


    Hong

    Friday, June 28, 2019 2:07 PM

Answers

  • Thank you for trying to help.

    I have found out the page being persisted in the memory was caused by CoreWindow.GetForCurrentThread().KeyUp event not unsubscribed from.  It is gone once this event is unsubscribed from.  


    Hong

    Saturday, June 29, 2019 12:48 PM

All replies

  • Hi

    You can make use of NavigationCacheMode.

    Saturday, June 29, 2019 10:23 AM
  • Thank you for trying to help.

    I have found out the page being persisted in the memory was caused by CoreWindow.GetForCurrentThread().KeyUp event not unsubscribed from.  It is gone once this event is unsubscribed from.  


    Hong

    Saturday, June 29, 2019 12:48 PM
  • Hi,

    Glad to hear find a way to make that. It's also appreciated for you to share the solution here.

    Best regards,

    Roy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, July 1, 2019 2:23 AM