How to dealloc a singleton?
I have a class named 'Capture' that is a subclass of NSObject and it also
adds views to a superview.
I have added a Settings.bundle which consists of slider. When the slider
value is 'ON/1' I show the views in 'Capture' in the main window as
subview. When the slider value is 'OFF/0' I have to remove the view added
from 'Capture' and release all the objects present in 'Capture'.
I simply don't want to hide the views created by 'Capture' class on to the
main view, when the slider value is 'OFF/0'.
I want to dealloc the 'Capture' when the app in sent to background and not
when the app terminates, so i cannot use the notification
UIApplicationWillTerminateNotification to dealloc a singleton.
If i just hide the views displayed by 'Capture', there will be unnecessary
use of memory for the 'Capture' class
So now how do i dealloc a singleton.
'Capture' class views will be on top of every view controller, even when
the events occurs. It is allocated once by class method called in
AppDelegate.
singleton is created this way:
static ScreenCapture *sharedScreen = nil;
+(Capture *)sharedScreenCapture
{
if (!sharedScreen)
{
sharedScreen = [[Capture alloc] init];
}
return sharedScreen;
}
No comments:
Post a Comment