iphone - How to dealloc a singleton? -
i have class named 'capture' subclass of nsobject , adds views superview.
i have added settings.bundle consists of slider. when slider value 'on/1' show views in 'capture' in main window subview. when slider value 'off/0' have remove view added 'capture' , release objects present in 'capture'.
i don't want hide views created 'capture' class on main view, when slider value 'off/0'.
i want dealloc 'capture' when app in sent background , not when app terminates, cannot use notification uiapplicationwillterminatenotification dealloc singleton.
if hide views displayed 'capture', there unnecessary use of memory 'capture' class
so how dealloc singleton.
'capture' class views on top of every view controller, when events occurs. allocated once class method called in appdelegate.
singleton created way:
static screencapture *sharedscreen = nil; +(capture *)sharedscreencapture { if (!sharedscreen) { sharedscreen = [[capture alloc] init]; } return sharedscreen; }
why not create reload
method clear cashes , nullify private variable?
something this:
+(void) reload { @synchronized(self) { // clear cashes... sharedscreen = nil; } }
and call after receiving uiapplicationwillterminatenotification
[screencapture reload];
Comments
Post a Comment