问题
Or, what is the opposite of +(void)initialize?
Here's my situation:
I have a class Unit, whose -(id)initWithName: function takes data from a global NSDictionary, which is created lazily, defined in the Unit.m file as:
static NSMutableDictionary *unitLibrary = nil;
Where do I call [unitLibrary release]?
回答1:
You can call it at a location in which you know the dictionary is not needed anymore. If it is needed throughout the entire lifecycle of the application, then you don't have to do anything as all memories will be reclaimed by the OS when the app terminates.
回答2:
There's no general-purpose answer. You should deallocate it when you're sure it won't be used again. Possible candidates might be in the applicationWillTerminate delegate message, or through an atexit() function.
来源:https://stackoverflow.com/questions/1528696/objective-c-where-do-you-dealloc-global-static-variables