cocoa - How do I dispose of my own sharedInstance in Objective-C? -


If I have a class that has its own shared interface (singleton pattern) or a shared example of another class So, how do I ensure that when my program turns out, the shared frequency is released properly? Better yet, can you tell me some documents about this?

Sample class (with all other methods removed for clarity):

  @interface Foo: NSObject {} + (Foo *) sharedInstance; @end  

.m file:

  Fixed Fu * Shared Instances; @ Implementation Foo + (Foo *) Shared Instruction {if (! Shared Instance) Shared Instance = [[FU Alok] IIT]; / Possible memory leak? Return Shareains; } @end  

In the above code, when can I issue ShareInstance?

Typically Barry said that there is no need to clean anything on exit, but you What can be done is setting up an NSAupplication representative that applies

  - (zero) applicationWernernet: (NSNotification *) A notification  

This The method is said right before you leave your application. In this method, you have to clean the cached shared example internally on your shared frequency You can call some steady method.

However, there is no existence of leaving something like a memory leak out of the application if your application ends, then it is never returned to all the proprietary memory systems, even if it is allocated Do not be. If that was not the case and your application was going to crash, then the memory used before the crash would eventually be lost in the system and it is not acceptable. On multi-tasking OS, an application which should not have any negative impact on the rest of the system due to crashes!


Comments