Is there any plans to make working signals in D?

Johannes Pfau nospam at example.com
Tue Apr 16 02:27:40 PDT 2013


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

> 
> > 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.
> 
> If you really want this behaviour, all you need is an array of
> delegates. But in my experience you don't usually want that, because
> you would have to take care of dropping any connections by hand, which
> is even more cumbersome than manual memory management in some regards.
> 
> Best regards,
> Robert
> 

But what if my only reference to the handler is in the signal and I
don't want it to get disconnected / cleaned up?

struct FileLogger
{
    File f;
    void onSomething()
    {
        f.writeln("Something happened");
    }
}

a.onSomething ~= &(new FileLogger()).onSomething;
(The FileLogger should only get destroyed if a is destroyed)

I have used that concept quite often in C#. Of course it's also
dangerous as it could cause memory leaks if used wrong. But I think we
should at least have the option of doing things like these. (Allowong
both strong & weak references as suggested by Kapps seems to be a good
solution)


More information about the Digitalmars-d mailing list