Would it make sense to make event handler references weak references?

  • Thread starter Thread starter Dmitriy Lapshin [C# / .NET MVP]
  • Start date Start date
D

Dmitriy Lapshin [C# / .NET MVP]

Hello everybody,

I have just been chatting with a colleague who is also an experienced .NET
programmer, and we have been discussing freeing memory by the GC in various
event handler scenarios (inspired by the "Freeing memory phobia" thread).

And what we've come up to is that event handler references could be made
weak references - meaning if the subscribed has been destroyed, it obviously
has no need to receive events anymore AND thus it would prevent the
receivers to be kept in memory just because they are subscribed to some
event.

What do you think?
 
Ian Griffiths and a few others checked this idea around a while back

http://www.interact-sw.co.uk/iangblog/2004/06/06/weakeventhandler

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

Hello everybody,

I have just been chatting with a colleague who is also an experienced .NET
programmer, and we have been discussing freeing memory by the GC in various
event handler scenarios (inspired by the "Freeing memory phobia" thread).

And what we've come up to is that event handler references could be made
weak references - meaning if the subscribed has been destroyed, it obviously
has no need to receive events anymore AND thus it would prevent the
receivers to be kept in memory just because they are subscribed to some
event.

What do you think?
 
It would definitely be very nice to have a key word or someting to specify
it optionaly.

Having it all the time is a bit far fetched however.
 
Back
Top