Skip to main content
GameDev.net gamedev.net
🔒 Locked

[.net] Instance delegates set to more persistent multicast delegate objects

Started by DrGUI Dec 19, 2004 at 4:18 PM 1 replies 550+ views
Original Post
DrGUI
DrGUI
For example, if class foo signed up an instance method to an event of class bar, then all references of the instance of foo were released and it was garbage collected, what would happen to the event? Would garbage collection remove it from bar's multicast delegate (event)? Or does one need to remove delegates first? Thanks
Arild Fines
Arild Fines
No instance of foo would be garbage collected as long as there remained a delegate pointing to one of its methods.
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
DrGUI
DrGUI
Quote:
Original post by Arild Fines
No instance of foo would be garbage collected as long as there remained a delegate pointing to one of its methods.

Thanks.

I guess I need to now keep the event handler delegates so I can remove them when the class is disposed or finalized (I have to use the dispose pattern now?) and that 'event -= new ...EventHandler(MyMethod)' would not work.
Correct?

Thanks for your quick reply

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.