realbasic-nug
[Top] [All Lists]

Re: FR: Weak Delegates (was Re: Some questions about delegates)

To: REALbasic NUG <realbasic-nug at lists dot realsoftware dot com>
Subject: Re: FR: Weak Delegates (was Re: Some questions about delegates)
From: Guyren Howe <guyren at mac dot com>
Date: Fri, 30 Nov 2007 22:35:26 -0600
Delivered-to: listarchive at realsoftware dot com
Delivered-to: realbasic-nug at lists dot realsoftware dot com
References: <BAY107-DAV4A856F93620F2D65BA3C693710 at phx dot gbl> <8162A20A-AA06-46C4-8293-78D1BE7AE094 at chaoticbox dot com> <653CDEAD-238A-41A5-B733-0F7D18A3742C at mac dot com> <16692A87-04A2-4423-BE7A-8054FED03C9F at declareSub dot com>
On Nov 30, 2007, at 7:38 PM, Charles Yeomans wrote:

>>> It's important to note that the delegate stores a strong ref to the
>>> instance behind your back, which can wreak havoc if you rely on
>>> things automatically cleaning up after themselves. In general I'd
>>> think delegates that held weak refs and fired exceptions when
>>> "Invoked" on a Nil object would be more useful, but I'm sure RS had
>>> their reasons for the current implementation.
>>
>> Requested:
>>
>> <http://www.realsoftware.com/feedback/viewreport.php?
>> reportid=oqccypjd>
>>
>
> I note, though, that delegates can be stored in WeakRef objects.  So
> I'm not sure that such a feature request is crucial.

I thought about that. But if you don't want the delegate to get GCd,  
you need a regular reference to the delegate somewhere, and then the  
problem just comes back.

There *is* a workaround, but it's to use a Class Interface with a weak  
reference, rather than a delegate. Which could be kind of clumsy,  
particularly if you want to be able to call from somewhere to either  
instance or static methods.

This makes me realize: if you could treat a delegate as an object  
satisfying a matching class interface, that would be a halfway  
solution, and a reasonable sort of abstraction to have, anyway.
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>


<Prev in Thread] Current Thread [Next in Thread>