Is it possible to dealloc a class object ?
I have a singleton class “singleton.h” which has a single instance and we can make use of its properties in any other view controllers.
+(singleton *)sharedMethod{
static singleton *myInstance=nil;
if(myInstance ==nil){
myInstance=[[singleton alloc] init]; myInstace.str=@"hello";
}
return myInstance;
}
what I want to know is.., Is there any way by which we can dealloc the class object in any of our viewControllers…and then again creat an instance of a new singleton class.., I tried doing so.., Xcode throws an error “cannot dealloc class object”.
The whole point of a singleton is that you do not deallocate it ever. Other classes may safe a pointer to the instance, so if you want to replace it you’d get strange behavior or even crashes sometimes. So you shouldn’t do it.
But it is possible, as long as you haven’t overwritten the
releaseandretainCountmethods. But your cited error message seems to suggest you’ve done something along the lines of[MyClass release];which doesn’t work, of course.BTW, you seem to have
singletonas a class name. Please try to stick to the coding conventions used by Apple to make your life and that of other people easier. Class names should always start with an uppercase character, method names should always start with a lowercase character.