ios - Releasing static resources in Objective-C -



ios - Releasing static resources in Objective-C -

this question has reply here:

objective-c/iphone memory management static variables 3 answers

if utilize static resource in objective-c class, create memory leak not ever releasing it? following:

@interface myclass : nsobject + (myclass *)sharedinstance; @end @implementation myclass + (myclass *)sharedinstance { static myclass * inst; if (!inst) inst = [myclass new]; homecoming inst; } @end

a) there scenario application using class closes , static declaration creates memory leak?

b) there class method, such + (void)unloadclassdefinition, called when class definitions beingness purged memory? (does happen?)

a leak chunk of memory have lost pointers. have pointer object, because variable exists duration of process. long don't reassign new object pointer without destroying old object, never have leak.

a) of process's memory reclaimed when terminates. there's no such thing leak can persist past application's end.

b) classes never unloaded 1 time loaded in apple's objc runtime.

if want able destroy object, have move variable out of method can access another, , along these lines:

static myclass * inst; + (myclass *)sharedinstance { if (!inst) inst = [myclass new]; homecoming inst; } // under arc; under mrr might monkey around retain , release // won't destroy instance if there other // strong references it. + (void)destroysharedinstance { inst = nil; }

but generally, if you're using singleton, want around life of application.

ios objective-c osx memory-management singleton

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -