Understanding of Dispose()

G

Guest

Hello

When Windows.Forms.Form procceds Dispose(), do it dispose all child controls
and fields?

I have Form variable Image which is connected to opened MemoryStrem (also
Form field)

When I call Form.Dispose(), does it mean that Image will be disposed and
MemoryStrem closed and disposed/distroyed

Thanks
Milan
 
C

Cor Ligthert [MVP]

Milan,

The dispose is probably the method which gives the most discussion in these
newsgroups.

Mainly because it is often read as a finalize method. That is it not. As the
ToString is it an overridable method. It is a method from Icomponentmodel
which is implemented in probably 80% of the most used classes (as Jon tested
once in 20% of the existent ones)

If you build your own classes than it is up to you what you do with it.

There are some classes where it is preferable that disposed is used. Think
for that on modal forms and drawing pens. In this is not the memory that is
occupied the most important but the used handles.

http://msdn.microsoft.com/library/d...l/frlrfsystemidisposableclassdisposetopic.asp

An object is released by the GC as part of the managed code as soon as it is
not needed anymore. This on a propriety time, however. Doing this all the
time would give worst performance.

I hope this gives an idea.

Cor
 

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