///************************** // MyClass.m #import "MyClass.h" static MyClass *myClass = NULL; @implementation MyClass (MyClass *)sharedMyClass { myClass = NULL; myClass = [[MyClass alloc] init]; return myClass; } @end Hi Experts, I just want to know myClass is a static ObjC object, it will be automatically released by ARC when no one is referencing it anymore, so no memory leak? is it correct?
dispatch_oncepattern. Here note you have a strong pointer to the class instatic MyClass *myClassso unless you set that tonilit will never be released. But this is not really a leak as, presumably, for this kind of a thing you need some instance of the class ready throughout the life of the app?dispatch_onceas it seems you need a singleton. This is quite normal but typically happens a bit differently to how you do it. Now what you do is fine (and common) also, of course, but sometimes you create a single instance of your class and access it e.g. like the default file manager or standard user preferences or the default notification center. I trust you know which classes I am talking about.