I have a big project where my application keeps retaining a page which I navigated away from. The page is only used minimal, and have a lot of graphics, I therefore want it to be completely removed from memory.
I therefore used the following
NavigationService.RemoveBackEntry();
Using the profiler I saw that, the above snippet made sure that I would only have 1 instance of the page. But as it is heavy with graphics I still want it to be completely removed from memory, i.e. no instances in the profiler.
In my big application I tried to unsubscribe to all events, introduce dispose/finalize and calling GC, it helped some but the instance still existed.
To exclude any stupid errors, I have made this small sample. Only Navigating between two dumb pages with a memory popup checker. But still 1-2 instances of the pages still exists. Is there anyway to force the removal of pages such that nothing of it is stored in memory?
I've added:
while (App.RootFrame.RemoveBackEntry() != null) ;
To the OnNavigated to, and it removes all the pages except the first page I start on. I've used the debug analysis toolkit, and can see that no matter what the first page I start on does not get removed, when I navigate away from it.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…