4

I needed to write an application for kiosk terminal and I choose WPF for this, because I need single window application. Implementation is simple - NavigationWindow and set of Pages, that uses in NavigationService.Navigate() method.

During using the application, I saw that it freezes, consuming large amount of memory. I found that when content is navigated to, NavigationService records the navigation as an entry in navigation history. I started to clean up history by using NavigationService.RemoveBackEntry() method.

Yes - history is cleared, but page's finallizers doesn't call. Pages are still being in memory and finallizers call only when the application is closed. I can just go from one page to another and then go back several times - application will consume about 150-200 Mb (starts from 5-6 Mb).

I checked the application with memory profiler and found that used memory doesn't increased - its about 5-8 Mb, but working set consume large amount of memory.

So I found a way to clear working set, but I didn't leave a thought that it is a wrong way. Solution must be more easier.

Documentation says that NavigationService does not store an instance of a content object in navigation history. Instead, NavigationService creates a new instance of the content object each time it is navigated to by using navigation history. This behavior is designed to avoid excessive memory consumption. But as I see it doesn't work this way.

I was thought that this behavior works only when NavigationService use URI for navigation (I call Navigate(new MyPage()) for navigating), but is doesn't work even with URI - pages instances still being in memory even if I clear the history journal.

So here is the questions:

1) Anyone else faced a similar problem?

2) Is that correct and best way to use NavigationWindow to build a single-window application?

Demos
  • 41
  • 2
  • Duplicate to http://stackoverflow.com/q/1925052/254109 Either try to set `KeepAlive = false` when using Uri navigation **only**. Or make your own navigation with plain `Window` (`ContentControl`) and `UserControls` instead of `Page`. – xmedeko Jun 04 '15 at 13:09

0 Answers0