Smart pointers instead of GC?

Michel Fortin michel.fortin at michelf.ca
Mon Feb 3 20:19:42 PST 2014


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.

-- 
Michel Fortin
michel.fortin at michelf.ca
http://michelf.ca



More information about the Digitalmars-d mailing list