Re: iOS: Preventing a singleton from being deallocated when the app is in the background.

2016-10-20 Thread Alex Zavatone
On Oct 20, 2016, at 6:37 PM, Greg Parker wrote: > >> On Oct 19, 2016, at 8:41 PM, Alex Zavatone 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 appe

Re: iOS: Preventing a singleton from being deallocated when the app is in the background.

2016-10-20 Thread Greg Parker
> On Oct 19, 2016, at 8:41 PM, Alex Zavatone 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

Re: iOS: Preventing a singleton from being deallocated when the app is in the background.

2016-10-20 Thread Alex Zavatone
On Oct 19, 2016, at 4:04 PM, Doug Hill wrote: > >> On Oct 19, 2016, at 2:00 PM, Jens Alfke wrote: >> >> >>> On Oct 19, 2016, at 1:23 PM, Steve Mills wrote: >>> >>> Pardon my obvious question, but this isn't a matter of your app napping >>> while in the background, is it? Or something like

Re: iOS: Preventing a singleton from being deallocated when the app is in the background.

2016-10-19 Thread Jens Alfke
> On Oct 19, 2016, at 8:41 PM, Alex Zavatone wrote: > > Yet we are seeing log output indicating the init method getting executed > twice. Set a breakpoint on it? Or add a counter to the init method so it crashes on the second call, so you get a crash log with a backtrace? —Jens ___

Re: iOS: Preventing a singleton from being deallocated when the app is in the background.

2016-10-19 Thread Alex Zavatone
On Oct 19, 2016, at 3:03 PM, Jens Alfke wrote: > >> On Oct 19, 2016, at 12:54 PM, Alex Zavatone wrote: >> >> Is there anything wrong with what I'm doing? > > Looks fine to me. Is any of this code using manual ref-counting? If so, I’d > suspect an over-release. Thank god, no. > >> shou

Re: iOS: Preventing a singleton from being deallocated when the app is in the background.

2016-10-19 Thread Greg Parker
> On Oct 19, 2016, at 2:29 PM, Steve Christensen wrote: > > The only difference between your code and mine is that you haven't > initialized onceToken = 0 so it has a random value. > > I looked around to see if that makes a difference and didn't get much > confirmation one way or another. One

Re: iOS: Preventing a singleton from being deallocated when the app is in the background.

2016-10-19 Thread Steve Christensen
The only difference between your code and mine is that you haven't initialized onceToken = 0 so it has a random value. I looked around to see if that makes a difference and didn't get much confirmation one way or another. One by Mike Ash (https://www.mikeash.com/pyblog/friday-qa-2014-06-06-secr

Re: iOS: Preventing a singleton from being deallocated when the app is in the background.

2016-10-19 Thread Jonathan Mitchell
> On 19 Oct 2016, at 22:14, Jens Alfke wrote: > So that’s not what the problem is. > It may be that the a separate instance of the singleton is getting created via the normal alloc - init sequence outside of the normal singleton accessor. That should be trivial to check for. _

Re: iOS: Preventing a singleton from being deallocated when the app is in the background.

2016-10-19 Thread Jens Alfke
> On Oct 19, 2016, at 2:14 PM, Jens Alfke wrote: > > No, nothing would be dealloced. The whole process would just be killed Sorry, I misspoke — I got it mixed up with termination for using too much memory. If the app gets quit in the background it does get notified that it’s quitting and can

Re: iOS: Preventing a singleton from being deallocated when the app is in the background.

2016-10-19 Thread Doug Hill
> On Oct 19, 2016, at 2:14 PM, Jens Alfke wrote: > > >> On Oct 19, 2016, at 2:04 PM, Doug Hill > > wrote: >> >> Presumably if the app is terminated due to inactivity everything would be >> dealloc'd including singletons. No idea if that is happening or not in this

Re: iOS: Preventing a singleton from being deallocated when the app is in the background.

2016-10-19 Thread Jens Alfke
> On Oct 19, 2016, at 2:04 PM, Doug Hill wrote: > > Presumably if the app is terminated due to inactivity everything would be > dealloc'd including singletons. No idea if that is happening or not in this > case though. No, nothing would be dealloced. The whole process would just be killed, an

Re: iOS: Preventing a singleton from being deallocated when the app is in the background.

2016-10-19 Thread Doug Hill
> On Oct 19, 2016, at 2:00 PM, Jens Alfke wrote: > > >> On Oct 19, 2016, at 1:23 PM, Steve Mills wrote: >> >> Pardon my obvious question, but this isn't a matter of your app napping >> while in the background, is it? Or something like that? > > Why would that cause a singleton to be dealloc

Re: iOS: Preventing a singleton from being deallocated when the app is in the background.

2016-10-19 Thread Jens Alfke
> On Oct 19, 2016, at 1:23 PM, Steve Mills wrote: > > Pardon my obvious question, but this isn't a matter of your app napping while > in the background, is it? Or something like that? Why would that cause a singleton to be dealloced? The app just stops getting CPU time for a while. —Jens ___

Re: iOS: Preventing a singleton from being deallocated when the app is in the background.

2016-10-19 Thread Steve Mills
Pardon my obvious question, but this isn't a matter of your app napping while in the background, is it? Or something like that? Steve via iPhone ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator co

Re: iOS: Preventing a singleton from being deallocated when the app is in the background.

2016-10-19 Thread Jens Alfke
> On Oct 19, 2016, at 12:54 PM, Alex Zavatone wrote: > > Is there anything wrong with what I'm doing? Looks fine to me. Is any of this code using manual ref-counting? If so, I’d suspect an over-release. > should I be using [GeofenceControllerSingleton alloc] init] instead of [[self > alloc

Re: iOS: Preventing a singleton from being deallocated when the app is in the background.

2016-10-19 Thread Alex Zavatone
On Oct 19, 2016, at 2:08 PM, Steve Christensen wrote: > This is the model I use for singletons and I've never had the singleton > instance deallocated out from under me. > > + (MyClass*) sharedThing > { > static dispatch_once_t sOnceToken = 0; > static MyClass* sSharedThing = nil; >

Re: iOS: Preventing a singleton from being deallocated when the app is in the background.

2016-10-19 Thread Jens Alfke
> On Oct 19, 2016, at 11:41 AM, Alex Zavatone 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 detec

Re: iOS: Preventing a singleton from being deallocated when the app is in the background.

2016-10-19 Thread Steve Christensen
This is the model I use for singletons and I've never had the singleton instance deallocated out from under me. + (MyClass*) sharedThing { static dispatch_once_t sOnceToken = 0; static MyClass* sSharedThing = nil; dispatch_once(&sOnceToken, ^{ sSha

iOS: Preventing a singleton from being deallocated when the app is in the background.

2016-10-19 Thread Alex Zavatone
We are running into what appears to be a case where a singleton that has been created through GCD dispatch_once may be getting deallocated by the OS. To check and see if this is the case, I have put logging code in the dealloc method, but our logs do show the init method being called twice even