I have an object X, and an object Y.
Y is the only object that has a reference to X.
X has an event. Objects A, B, C register for this event but dont keep a
reference to object X.
When whoever owns Y is done with it, and Y is garbag collected, what happens
to X and to the Objects that registered for the event? will those event
registration prevent X from being garbage collected? 3 1537
cs,
When A, B, and C register for the event on X, X has a reference to those
objects (assuming they are instances). If Y releases X, and nothing else
has references to A, B, or C, then X, A, B, and C all become eligible for
GC.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"cs" <[rem]casolorz[rem]@hot[rem]mail.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl... I have an object X, and an object Y. Y is the only object that has a reference to X. X has an event. Objects A, B, C register for this event but dont keep a reference to object X. When whoever owns Y is done with it, and Y is garbag collected, what
happens to X and to the Objects that registered for the event? will those event registration prevent X from being garbage collected?
Yes
The problem is, however, that if A, B and C goes out of scope, they're still
registered for the event in X, and will cause major problems when not
accessible. Looking forward to some kind of weak reference in .NET where
objects can be unregistered when CG'ed.
--
venlig hilsen / with regards
anders borum
--
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:OG**************@tk2msftngp13.phx.gbl... cs,
When A, B, and C register for the event on X, X has a reference to
those objects (assuming they are instances). If Y releases X, and nothing else has references to A, B, or C, then X, A, B, and C all become eligible for GC.
Hope this helps.
nice thats exactly how I was hoping it would behave. In my case A,B,C are
only created to handdle the event, and no one keeps a reference to them,
other than the event they registered for. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: tony kulik |
last post by:
This code works fine in ie and opera but not at all in Mozilla.
Anybody got a clue as to how to get it right?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<script...
|
by: Dennis C. Drumm |
last post by:
I have a class derived from a SortedList called SystemList that contains a
list of objects indexed with a string value.
The definition of the objects contained in the SortedList have a boolean...
|
by: bhavin |
last post by:
Hi,
Can someone point me to some good best practices kind of documentation on
use of events compared to method overriding.
Ex. In Windows Forms when should i have an event handler for Paint, and...
|
by: Charles Law |
last post by:
Mr "yEaH rIgHt" posted the following link about a week ago in answer to my
question about removing event handlers.
> http://www.vbinfozine.com/t_bindevt.shtml
Following on from that post, the...
|
by: Amit |
last post by:
Hello!
Is it possible to find how many event handlers an event has at runtime? How
about finding whether or not an event has event handlers? In C# you can
compare the event with null to check if...
|
by: Kevin Attard |
last post by:
I am using a GridView inside a UserControl which has a template column for
deleting the rows. Before databinding the gridview i am attaching the
RowCommand and RowDataBound event.
I am using the...
|
by: Hamed |
last post by:
Hello
I am developing a utility to be reused in other programs. It
I have an object of type Control (a TextBox, ComboBox, etc.) that other
programmers use it in applications. they may set some...
|
by: Hamed |
last post by:
Hello
It seems that I should implement ICloneable to implement my own clone
object. the critical point for me is to make a control object based on
another control object that all of its event...
|
by: Jake K |
last post by:
Where is the best place to define event handlers? I need to define event
handlers for a COM object referenced in my project and am doing so in the
fowm load. Is this the best place?
|
by: Tony Johansson |
last post by:
Hello!
I know it's possible to have several event handler for a single event but I
can't
see any point using several event handler for this.
I'm probably wrong so can anybody tell me what...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |