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: Greg Parker <email@hidden>
- Date: Thu, 20 Oct 2016 16:37:15 -0700
> On Oct 19, 2016, at 8:41 PM, Alex Zavatone <email@hidden> wrote:
>
> In that case we would find out really quickly, because this is one of the classes that starts up as soon as the app makes several server calls. When our error happens that appears like a dealloc, the app has been running and using this class for a while and is sitting around on iOS while it is in the background.
>
> Yet we are seeing log output indicating the init method getting executed twice.
Verify that you are seeing two init logs from one process rather than one init log each from two processes. (Adding the PID to the log should resolve that, if you don't have it already.)
Verify that your singleton enforcement is thread-safe. Thread-unsafe singleton enforcement can create a second singleton if there is a race.
Log the stack trace of each init call. Perhaps one caller is bypassing your singleton enforcement somehow. (For example, you wrote singleton enforcement in +alloc but some call sites are using +allocWithZone:.)
Log the address of the object being returned by init. Perhaps there is only one object but init is being called a second time on it.
Log or crash in dealloc, if your singleton enforcement might allow the object to be deallocated and then a new one to be created.
--
Greg Parker email@hidden <mailto:email@hidden> Runtime Wrangler
_______________________________________________
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