ios - Does setting an NSMutableDictionary to nil release the reference to all it's content? -
so let's have nsmutabledictionary
filled objects this:
nsmutabledictionary* dict = [nsmutabledictionary dictionary]; (int i=0; i<10; i++) { someclass* tmp = [[someclass alloc] init]; [dict setobject:tmp forkey:[nsstring stringwithformat:@"%i", i]]; }
if set dictionary equal nil
, release objects put in (thus freeing allocated memory each one)?
i want use nsmutabledictionary
cache basically, , whenever app receives call system didreceivememorywarning
, want clear out cache , release every object in it.
so setting dictionary nil
enough, or have call method wipe out data , free memory allocated creating someclass
instances?
if there no references dictionary
dict = nil;
will cause dict deallocation. deallocation method called - [nsmutabledictionary dealloc]. , inside method references content released.
you cal call nsmutabledictionary's
- (void)removeallobjects;
method instead.
i suggest @ nscache class - handles didreceivememorywarning itself:
an nscache object collection-like container, or cache, stores key-value pairs, similar nsdictionary class. developers incorporate caches temporarily store objects transient data expensive create. reusing these objects can provide performance benefits, because values not have recalculated. however, objects not critical application , can discarded if memory tight. if discarded, values have recomputed again when needed.
and nsmaptable:
nsmaptable mutable collection modeled after nsdictionary provides different options.
Comments
Post a Comment