Dispose...AGAIN

G

Guest

When using a Context Menu, I've added menuitems to the ContextMenu and have
the following questions:

If I delete a menuitem, do I have to use it's dispose method also?

If I use mycontextmenu.menuitems.Clear, does this dospose of the MenuItems
or do I have to still call the Dispose method on each item

If I use the ContextMenu.Dispose, does it call all the current MenuItems
Dispose method,

Really, I'm struggling with when to call dispose and when not to. It seems
a burden that M'soft put on the programmers that could have been avoided by a
bit smarter .Net Framework.
 
C

Cor Ligthert

Dennis,

The GC clears all objects that have no reference anymore to it or cannot be
referenced from anypoint anymore.

This is done in three different generations.

You can read it in this document. (I am not so glad how they wrote disposing
in this document, know that unmanaged resources are not unmanaged objects.
Unmanaged resources are disposed by managed objects which implements
Idisposable).

The complete document.
http://msdn.microsoft.com/architecture/default.aspx?pull=/library/en-us/dnpag/html/scalenet.asp

The GC in this document
http://msdn.microsoft.com/architect...ml/scalenetchapt05.asp#scalenetchapt05_topic9

I hope this helps?

Cor
 
G

Guest

Thanks Cor. I haven't seen this link before and looking at it, it will take
some time to read thru it. Although I understand what managed, unmangaged
means and what dispose vs Garbage collection means, I doubt if I'll ever
fully understand when to dispose of objects. Thanks again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top