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: Alex Zavatone <email@hidden>
- Date: Thu, 20 Oct 2016 18:53:28 -0500
On Oct 20, 2016, at 6:37 PM, Greg Parker wrote:
>
>> 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.
That's a big one right there. The address would be different if this was another instance.
Thanks Greg, I'll make sure that we track this more closely to verify if this is or is not happening.
We did have one case months ago where the object was losing the reference to the singleton's static ref. No idea how that happened, but directly calling the singleton through it's sharedReference solved the issue.
Thanks.
>
> Log or crash in dealloc, if your singleton enforcement might allow the object to be deallocated and then a new one to be created.
>
>
_______________________________________________
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