Reputation: 10339
I have a cleanup routine that converts references to stale objects (which are good to have around given sufficient memory) into weak references. I want this routine to be called whenever my application is running out of memory. I have a background thread which calls this method at periodic intervals. But I am concerned about what could happen when there is a memory crunch situation between successive runs of this routine.
What should I do to have this method called whenever the application would need more memory?
Upvotes: 0
Views: 57
Reputation: 3915
You might think of using a PerformanceCounter to keep track of process memory usage, and when your process memory usage goes past a certain limit you can call your routine.
Check these links: http://social.msdn.microsoft.com/Forums/vstudio/en-US/7d8a6640-919d-47d8-8e73-586fb7ac261e/get-processs-memory?forum=csharpgeneral
http://msdn.microsoft.com/it-it/library/system.diagnostics.performancecounter(v=vs.110).aspx
Upvotes: 1