Re: iOS: Preventing a singleton from being deallocated when the app is in the background.
Re: iOS: Preventing a singleton from being deallocated when the app is in the background.
- Subject: Re: iOS: Preventing a singleton from being deallocated when the app is in the background.
- From: Jens Alfke <email@hidden>
- Date: Wed, 19 Oct 2016 12:20:11 -0700
> On Oct 19, 2016, at 11:41 AM, Alex Zavatone <email@hidden> 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 (email@hidden)
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:
This email sent to email@hidden