Smart pointers instead of GC?

Manu turkeyman at gmail.com
Mon Feb 3 20:29:34 PST 2014


On 4 February 2014 14:27, Manu <turkeyman at gmail.com> wrote:

> On 4 February 2014 14:19, Michel Fortin <michel.fortin at michelf.ca> wrote:
>
>> On 2014-02-04 03:45:33 +0000, Manu <turkeyman at gmail.com> said:
>>
>>  The majority of trivial allocations don't produce cycles; closures,
>>> strings, temporary arrays and working sets.
>>>
>>
>> Oh, no. Beware of closures. That's a frequent problem in Objective-C ARC,
>> even for those who understand ARC well. You have to be very careful of
>> closures creating cycles if you use them as callbacks. For instance, you
>> have a view that has a pointer to the model and sets a callback for the
>> model to call when something change to update the view; that's a cycle and
>> you need to use a weak ref to the view within the closure. Pretty common
>> pattern.
>
>
> Ah right. Interesting.
> It sounds like this could be addressed easily though by the API that
> manages the 'event' handler. If you use a raw delegate, maybe it's a
> problem, but it sounds like an event-programming construct, and that
> usually requires an event class that can handle multiple subscribers, as
> soon as that exists, it's easy to hide the weak reference behind the event
> api...
>

I can say that all the closures that I've observed in my D apps so far have
been entirely trivial.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20140204/708c8553/attachment.html>


More information about the Digitalmars-d mailing list