ios - Is a strong retain cycle a relevant consideration for a singleton class that should exist for the life of an app? -
i have singleton class in app created @ app launch , in use. going introduce nstimer calls 1 of singleton's methods periodically, understanding timer retain strong reference singleton class (since singleton class target). correct? more importantly, strong retain cycle problem singleton class should live duration of app? if so, why?
i consider problem. singleton class hard refactor , reuse. adding retain cycle 1 going make class harder change or reuse in future. when discover need class (or @ least set of responsibilities timer part of) not singleton you'll need remember or identify memory leak , fix part of refactor. future sad.
instead can write class follows patterns (for memory management , otherwise) regardless of if accessed singleton or not. in case might mean keeping weak reference timer ("note in particular run loops maintain strong references timers, don’t have maintain own strong reference timer after have added run loop.") , invalidating timer if object deallocated.
Comments
Post a Comment