> On Oct 19, 2016, at 11:41 AM, Alex Zavatone <z...@mac.com> wrote:
> 
> I have seen on discussion where people suggest keeping a private strong 
> property in the singleton with a reference to self to prevent this from 
> happening.

Bad idea: it relies on the implementation detail that the runtime can’t detect 
reference cycles. It would fail in the (obsolete) garbage collected 
environment, and it could fail in the future if Apple extends the Obj-C runtime 
to be able to detect unreachable reference cycles and collect them.

(Also, even in the present day it will trigger the leak detectors in 
Instruments and in Xcode 8’s new memory visualizer.)

If you want something to stick around forever, make a static variable that 
points to it (as in Steve’s example.)

—Jens
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to