views:

90

answers:

3

I have a c# application that is composed of various screens which is each a respective user control. The application requires a lot of switching between the various screens and is also graphic intensive. Each control is disposed once the next control is invoked and the garbage collector is called to release the system resources. The thing is for some reason the system memory is never released and at some point after multiple screen changes it inevitably crashes. Any Ideas would be greatly appreciated.

+2  A: 

If I had to guess, you're registering lots of events with these controls but not de-registering before they get "disposed", so they're not getting collected by the GC.

This is a hugely complex subject. I'd strongly suggest investing in a decent memory profilter (a hundie or two) to help you narrow down where your application is crashing.

Will
A: 

It seems to me that you're not freeing all controls. It could be because you just forget to release one, but once it's unused, the garbage collector should still pick it up.

A more probable cause would be a circular reference, where two controls are using each other, thus keeping the other alive. There could be a whole circle of controls that keep each other active, and if they start to link themselves to more controls, the system would eat up all resources sooner or later.

Workshop Alex
A: 

Try using a memory profiler, (e.g. ants) it will tell you what is keeping the object alive. Trying to 2nd guess this type of problem is very hard.

Red-gate gives 14 days tail that should be more then enough time to tack down this problem and decide if a memory profiler provides you with long term value.

There are lots of other memory profilers on the market (e.g. .NET Memory Profiler) most of them have free tails, however I have found that the Red-Gate tools are easy to use, so tend try them first.

Ian Ringrose