signal slots library

Bastiaan Veelo Bastiaan at Veelo.net
Fri Oct 13 07:32:08 PDT 2006


> To answer your question honestly I'm not exactly sure if unreferenced 
> objects get garbage collected, but if they get deleted they are safely 
> disconnected:

OK, that is enough for C++ (Qt) style programming where the programmer 
has to take care of deletion. However, in D it would be really nice to 
let the garbage collector do that.

> Instead of storing references to an object in the signal, I took the 
> approach of giving each object which has slots an unique identifier 
> (mixin, no base class needed). This identifier is stored in a AA and 
> reference counted, each managed slot in the signal also know's it's ID, 
> so the signal can check the validity of a slot.

So each time a signal is sent to a slot, it searches the AA to check 
whether the object is still alive? That seems a bit of an unnecessary 
overhead.

> This avoids the problem 
> of objects / slots and signals needing to know about each other.

Is it a problem?

> As for garbage collection, I don't know (or forgot) if taking a delegate 
> from an object counts as a reference that keeps the object alive. I 
> would assume so, as it has a pointer to the object.

Correct. The concept of weak pointers has been proposed to the newsgroup 
a long time ago, which would do as you hoped they did.

> I'll check Uwe 
> Salomon's code for this issue.

He uses malloc and free, if I remember well.


Have fun!

Bastiaan.



More information about the Digitalmars-d-announce mailing list