John,
When you use AddHandler (or WithEvents) the object handling the event will
hold a reference to the object raising the event. As the object handling the
event has the list of delegates. If both objects go "out of scope" at the
same time (such as when you close a Form) then the GC will collect all
objects.
However if object raising the event goes "out of scope" way before the
object handling the event, then the object raising event will survive until
the object handling the event is "out of scope".
By "out of scope" I mean that all references to the said objects are
released, except for implicit & explicit references to each other.
| Do I have to call RemoveHandler every time I load a
| new document so the original document will be free to be garbage
collected?
You shouldn't need to as the Document is holding references to your object
with the handlers.
--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley -
http://www.tsbradley.net
"TrtnJohn" <Tr******@discu ssions.microsof t.com> wrote in message
news:47******** *************** ***********@mic rosoft.com...
| If you call AddHandler and hook events of one object to a method in a
class
| will the event source object still be available for garbage collection if
the
| original reference is set to Nothing? Or do you have to call
RemoveHandler
| as well?
|
| For example: I am using the ActiveX version of the WebBrowser control.
In
| the DocumentComplet e event I set up my event handlers for the Document
object
| loaded by the browser. Do I have to call RemoveHandler every time I load
a
| new document so the original document will be free to be garbage
collected?
|
| I guess I am confused on what referencing occurs when you use AddHandler.
I
| couldn't find a good explanation on it in the MSDN Help. (I am sure it is
| there somwhere). Any links are appreciated.
|
| Thanks,
| John
|