garbage collection

  • Thread starter Thread starter Mike J
  • Start date Start date
M

Mike J

i need a example of disposing() and or
explicily kicking off the garbage collector

thanks
MJ
 
i need a example of disposing() and or
explicily kicking off the garbage collector

thanks
MJ

i need a example of disposing()

MyDisposableObject.Dispose()

or

Using (MyDisposableObject)
....
End Using
and or explicily kicking off the garbage collector

GC.Collect()

Please note that it is almost always a terrible idea to force the GC
to collect, especially if you are disposing of your objects correctly.
Please search this newsgroup (and/or related newsgroups) for a full
overview of why this is a bad idea.

Thanks,

Seth Rowe
 
Hi,


According to a Jeffery Richter Geekspeak web-cast I listened to recently,
one of the reasons is that it will effectively reset the GC statistics on
object lifetimes, or rather make them incorrect. The GC maintains
information about object lifetimes in order to more efficiently dispose of
objects depending on how long it expects them to live. Anyway there is
almost never any good reason to force a collect.

The OP should look up the IDisposable pattern (which Richter actually hates,
even though he coded it!).



Robin
 
In the class you want to enforce

implements IDisposable '---- press enter after this line and all code wil be
generated for you

now explicitly dispose of anny sub objects in the interface signature

end use your class with the using keyword in the rest of your project
 
Back
Top