I'm looking to move forward with a strategy that will detect when the system is about to run out of memory and restart the system using Application.Restart();
The WebBorwser control is causing me take this route because even after disposing a webbrowser control attached to a form the memory usage does not decrease and everywhere I've read says this is a IE issue and we are at their mercy. (Although I do notice if I open IE, run the same websites, the memory increases but properly reduces when I close the tab. ...)
I'm not looking to move to webkit because watin is not compatible and I'm not looking to to use GeckoFX because it does not support javascript or jquery support and I'm not looking to use external browser instances because embedded browser controls are part of my interface design.
So now what I want to do is create a method that dynamically checks available memory against total memory and performs a restart when the situation gets critical to properly dispose of resources the GC cannot reach and I cannot programatically figure out how to destroy.
I believe I can do this and restart my automation from where I left off and cycle this daemon on and on.
Can anyone help me figure out how to code the memory check? It should be easy enough. I found this thread but I'm having some trouble implementing it without running into errors... maybe another approach will be better? How do you get total amount of RAM the computer has?
Thanks guys! I hope this helps,
This doesn't make a lot of sense. OOM occurs because the CLR memory manager could not allocate the desired chuck of memory. This may be due to a number of reasons. Looking at available RAM (which is completely irrelevant) or even available GC memory before all allocations will not guarantee the absence of OOMs. E.g. if you have LOH fragmentation the total number of available bytes may exceed the need for the allocation, but if the CLR cannot allocate a single, contiguous chunk of memory from the free-list the request will still fail.
Asp.Net will evict stuff from the httpcache when it notices that it goes low on available memory, you could take a trip into that part of the framework through Reflector and learn from how it does the job there...