How do I know if an object will be disposed automatically when i invoke the close() method on the form?
Okay, I have a problem with my program climbing in memory usage until it crashes the computer. I am almost completely sure that this is because one or more objects are not being disposed of from when i open and close secondary forms. How can I tell which variables arent being disposed of?
VulpesPosted Mar 5, 2011, 8:54 AM
Suthish NairPosted Mar 7, 2011, 2:24 PM
Sam HobbsPosted Mar 4, 2011, 10:46 PM
I am not an expert but I think your quote from the MSDN is misleading. It is surprising that it says that when "a form is closed, all resources created within the object are closed and the form is disposed". I just don't believe it. It is totally possible to allocate a form, then set a member of the form to something, then show the form, and then the form changes the value, then the form closes and the object that created the form can then get the modified value. It would be a big problem if all members of the form are disposed of when the form is closed. Probably the key word here is "resources" which is not synonymous with members. It is probably referring to resources at the Windows API level.
Also, an MDI child form is never a startup form! So saying that a form is not disposed of when it is closed when it is part of a MDI application sounds to me to also be misleading, but since it says "and" shown using ShowDialog, it is probably true and must be read carefully, as is the case for many things in the MSDN.
Sam HobbsPosted Mar 4, 2011, 10:28 PM
There are many useful articles in this web site. Have a look at the following. If they don't help then you need to look for similar articles in the MSDN and other sites.
.NET Best Practice No: 1:- Detecting High Memory consuming functions in .NET code
Best Practices No 5: - Detecting .NET application memory leaks
Garbage Collection: Memory Management in .Net
The "Using" Statement in C#
patrickPosted Mar 4, 2011, 7:17 PM
VulpesPosted Mar 4, 2011, 12:58 PM
VulpesPosted Mar 4, 2011, 12:05 PM
If a form is hidden but some code on it is running in the background, then the GC will perform normally. So, if there are no longer any references to a particular object, it will be disposed of in due course.
patrickPosted Mar 4, 2011, 11:45 AM
VulpesPosted Mar 4, 2011, 11:42 AM