473,387 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

What is the correct way of destroying an object who is listening to delegate events?

If I have objA that has registered for delegate events from objB and
objA is set to null (or is destroyed by going out of scope), should
objA do anything to unregister from these events before it is
destroyed? For instance in the destructor should it be doing something
like this:

objA_destructor()
{
objB.A_delegate -= OnDelegateEvent(MyFunction)
}

Or can this be done automatically somehow???

Thanks in advance,
Darren.
Nov 16 '05 #1
1 1037
Dan
Darren,

This should be handled by the garbage collector in the .Net CLR, so you
don't need to do anything.

Dan.

"Darren" <wa********@hotmail.com> wrote in message
news:cd**************************@posting.google.c om...
If I have objA that has registered for delegate events from objB and
objA is set to null (or is destroyed by going out of scope), should
objA do anything to unregister from these events before it is
destroyed? For instance in the destructor should it be doing something
like this:

objA_destructor()
{
objB.A_delegate -= OnDelegateEvent(MyFunction)
}

Or can this be done automatically somehow???

Thanks in advance,
Darren.

Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Dan Cimpoiesu | last post by:
I have a remoting object, derived from MarshalByRefComponent, that I instantiate on the client side, with Activator.GetObject. Can I receive events fired on the server, on the client? How?
23
by: jm | last post by:
This works, but I don't know why. static void Main() { // Queue the task. ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadProc),new Form1()); Application.Run(); }
2
by: FredC | last post by:
OS Name Microsoft Windows XP Professional Version 5.1.2600 Service Pack 2 Build 2600 Total Physical Memory 1,024.00 MB MDE 2003 Version 7.1.3008 ..NET Framework 1.1 Version 1.1.4322 SP1...
9
by: Jay | last post by:
Everywhere I go (read/browse) I see these parameters.... ByVal sender As Object, ByVal e As System.EventArgs Yet I never see them used within the function/method. Could someone tell me what they...
2
by: al | last post by:
Greetings, Can someone please tell me the what is the defference betweeen delegates and events handler??? MTIA, Grawsha
4
by: Jarod_24 | last post by:
What is the point with Delegates in VB.Net What can these things do that we can not allready do with the use of Interfaces, Events and Event handlers and so on... I'd like a discussion on this,...
9
by: Gummy | last post by:
Hello, I created a user control that has a ListBox and a RadioButtonList (and other stuff). The idea is that I put the user control on the ASPX page multiple times and each user control will...
5
by: jm | last post by:
If I have multiple subscribers to a delegate, what keeps track of them? Are they out there on the heap? When I declare a delegate: public delegate void MyDelegate (object myObject,...
5
by: AliRezaGoogle | last post by:
Hi, I have a conceptual question on Events and Multicast Delegates. Let me explain: As we know an event is a multicast delegate. What we declare as an event is inherently a multicast delegate....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.