views:

68

answers:

2

I have a WPF (.Net 3.5 sp1) application that loads a bunch of data on start up (it takes a few seconds to start up) but it performs fine after the data is loaded. While the app is running, if I don't touch it for some time (say, a few hours), and then I alternate to it, it then "wakes up" very slowly.

My questions:
1) Why is that? Is that because .Net deallocates the large data I load from memory and it has to somehow recover that?
2) What can I do in my app to prevent this behavior even if I know I would be sequestering memory until the app is finalized?

Thanks

+1  A: 

As Jay suggested, this is almost certainly happening because the application's data is being written out to the pagefile.

If the computer is under your control, try turning off the pagefile. If the computer has a lot of RAM, and you don't run a lot of programs at once, you may find that you don't actually need the pagefile.

Roland Acton
Hi Roland,the computer is not under my control. Users' computers.
Gustavo Cavalcanti
There's not much you can do then. You can try running through your application's data periodically and touching objects (as velijkoz suggested), but you can't touch everything. The GUI-related stuff will still get swapped out. Windows doesn't swap entire applications, it swaps memory pages.
Roland Acton
A: 

I can see two ways out:

  1. access all of your cached data in a thread separate from GUI (which would probably be a lot of work to rewrite),
  2. add some timer triggered call that would always work (maybe just fetch some random data from cache) and it will keep your application to be non-idle, thus preventing it's content to go to pagefile.
veljkoz
I like your 2nd idea. Thanks.
Gustavo Cavalcanti