Is there any plans to make working signals in D?

Johannes Pfau nospam at example.com
Sun Apr 14 10:34:59 PDT 2013


Am Sun, 14 Apr 2013 19:07:58 +0200
schrieb Robert <jfanatiker at gmx.at>:

> > Does it mean you disagree with proposed compiler changes and with
> > the idea we have to create weak reference functionality instead of 
> > recreating it every time it is needed (beside of theoretical danger
> > such approach already showed it as a bad thing with
> > `std.stdio.File` as I wrote)?
> > 
> 
> 
> A weak reference could actually be implemented in the library
> relatively easy. ( I basically did it for std.signals2 ) But for
> std.signals a weak ref is not really enough, because ideally the slot
> gets removed if the target gets destroyed, not only set to null.
> Updating a collection on destruction of an object is not that easy as
> you pointed out (thank you for that), but I don't see how weak
> references would help there.
> 
> But you just made me think: If it is ok that a signal does not release
> the memory for the slot immediately when the object gets destroyed but
> only on the next call to emit(), then the implementation would be much
> simpler ...
> 
> Best regards,
> Robert
> 

IMHO if a object still is connected to a active signal it should not be
collected. So the place where the signal stores the handler should be
scanned by the GC as usual. Then just document clearly that you have to
remove a handler to make sure that garbage collection can really kick
in.


More information about the Digitalmars-d mailing list