472,989 Members | 3,054 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Weak event subscriptions and concurrency considerations

Hi all,

I've been considering that my objects should subscribe to an event via
a weak reference, however I've found several warnings that this
approach comes with concurrency considerations, like the fact that the
event handler method on the subscriber could be called and be
executing while the object is being garbage collected.

Not being super strong in the multithreaded department, I am having a
hard time coming up with other possibly problematic concurrency
considerations. I realize this question is quite vague, but I am not
even sure where to start educating myself on such topics.

Anyone have any links or literature they can point me to?

thanks,
HC
Jun 30 '08 #1
1 1735
On Mon, 30 Jun 2008 12:35:06 -0700, <He*************@googlemail.comwrote:
I've been considering that my objects should subscribe to an event via
a weak reference, however I've found several warnings that this
approach comes with concurrency considerations, like the fact that the
event handler method on the subscriber could be called and be
executing while the object is being garbage collected.
Can you be more specific? I don't see any way for a default-declared
event (i.e. no custom add/remove implementation) to be subscribed "via a
weak reference". Are you specifically implying that you'd also provide
custom add/remove implementations? What would the exact implementation of
this approach look like?

As for the rest of your question...
Not being super strong in the multithreaded department, I am having a
hard time coming up with other possibly problematic concurrency
considerations. I realize this question is quite vague, but I am not
even sure where to start educating myself on such topics.
Well, the whole point of a weak reference is to allow the garbage
collector to collect the object if necessary. There are a variety of
reasons that might happen, but they all pretty much come down to the same
thing: if the only reference to an object is in a WeakReference instance,
the object could be garbage collection. You always have to copy the
reference to a regular "strong reference" variable before you use it,
checking to make sure it's still valid.

Other than that, I don't see what "other possibly problematic concurrency
consideration" might exist. Seems to me that the one consideration about
the object being collected should complicate your life quite enough. :)
Anyone have any links or literature they can point me to?
Well, you should probably read the docs for the WeakReference class, as
well as the various articles on MSDN that provide more details regarding
how the garbage collection system works. Without a firm understanding of
those topics, I don't think you should be messing around with weak
references.

That said, for that matter it's not really clear to me what you hope to
gain by using a weak reference for your event subscriptions. Sounds
pretty odd to me.

Pete
Jul 1 '08 #2

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

Similar topics

94
by: Gabriel Zachmann | last post by:
Is it correct to say that strong/weak typing does not make a difference if one does not use any pointers (or adress-taking operator)? More concretely, I am thinking particularly of Python vs C++....
2
by: Matthew Herrmann | last post by:
Hi, I've heard from groups that listeners to event handlers cause references to be kept alive, if the targets are marked to stay alive. I need to make sure that attaching events to objects will...
4
by: TS | last post by:
I am creating a User control and i create some dynamic controls in the init handler. one of the controls is a custom validator which i assign a serverValidate event handler. I usally always do my...
2
by: moondaddy | last post by:
I have an asp.net 2.0 application and put a html button on a web page. I double clicked on the button and it crated the event handler for me and created the stub js function for it like this: ...
4
by: DeveloperX | last post by:
Hi, I've just written the following code to describe the issue I have. In a nutshell if an object subscribes to an event on a long lived object and I then ditch the reference to the subscriber (set...
4
by: =?Utf-8?B?V2lsc29uIEMuSy4gTmc=?= | last post by:
Hi Experts, I am doing a prototype of providing data access (read, write & search) through Web Service. We observed that the data storing in SQL Server 2005, the memory size is always within...
6
by: kirk | last post by:
I have three events, using event handler methods as depicted below. Two of those event handler methods need to reset specific data whenever the other event left fires. I wasn't sure how to...
0
by: kirk | last post by:
I have three events that I have created and manage with timers. Two of the timer event handlers, the last two in the code below, need to reset state management data, if the first event handler...
1
by: =?Utf-8?B?c2lwcHl1Y29ubg==?= | last post by:
I have a assembly from a third party that exposes an Event I want to Trap the event and tie to a Method in a Class where I am consuming their assembly. The class is actually a UserControl How...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
3
SueHopson
by: SueHopson | last post by:
Hi All, I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...

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.