Why doesn't the Garbage Collector kick in when my app is idle?

Posted by

I don't know why, but I always seem to post in spurts :)

One of the things with the Garbage Collector is that it only kicks in when you actually run out of memory. Now, that's not entirely true, but the point is that it only kicks in when you allocate memory. But why not kick it in when my application is idle?

The thing is, processes in Windows don't run in isolation. And if you're running a program, it's taking up space in your page file. And that space isn't infinite. So while an idle program's memory will be swapped out to disk (thus freeing up physical memory) it'll still be taking up space in the pagefile - and that space will never be reclaimed until my program becomes active again and start allocating memory.

I can understand that running the GC while a program is idle will immediately swap all that memory back in to physical RAM, even though it's not doing anything, but if you can free up some swap space (especially if you're running low on swap space) then mightn't that be worth it?

blog comments powered by Disqus