Reputation: 1265
I have a UI, winform, It has loads of controls like tabcontrols, Plenty of text boxes(min 25 spread across tabs) comboxes, checkboxes, buttons, labels, tree control etc.
most of these controls register for ctrl events like textchanged, click etc... Since i am getting this out of memory exception and all i have few queries:
Questions:
Some Info: The application was put on a stability test for upto 100 iterations on a 2GB ram machine. Each iteration it would execute the same test(launching teh dialog, doing some clicks or editing some values, and closing). It was on running for almost 8 hrs. on the 45 th or the 46 th iteration it threw this exception. Yes all the controls in the dialog have one event or ther other registered. some text changed some checkedchanged or click etc
Upvotes: 0
Views: 252
Reputation: 38758
I don't think there's enough information here to tell you exactly what's going on. This will take some careful analysis of the code on your part, but the first thing to do is to run your app through a memory profiler. For example, ANTS Memory Profiler, but really anything you have access to will do fine) to see what's really going on.
Normally, you wouldn't need to explicitly dispose of every control, but if you're subscribing to events, that can cause things to hang around in memory longer than usual. This question has the gory details, but in a nutshell, you want to unsubscribe or use weak references to fix that; no need to enumerate all form controls and call Dispose
. If I recall, it should be called on Form.Close()
anyway, unless it's an MDI form and it's not visible when Close
is called.
You should also look at what data you're storing and how, as well as whether or not you're properly disposing of whatever resources your application may be using.
If you're running on a 32-bit system, you might also be running against the per-process memory limit of 2GB, which you can hit if you, say, keep a List
around that grows to 1GB and has to resize.
So, arm yourself with a profiler and get investigating. :)
Upvotes: 1