Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You need to analyse this in light of Apple's <a href="http://developer.apple.com/library/mac/#documentation/cocoa/Conceptual/MemoryMgmt/Articles/mmRules.html" rel="nofollow">Memory Management Rules</a>.</p> <p>Starting with this line:</p> <pre><code>self.mutableDictionary = [self.immutableDictionary mutableDeepCopy]; </code></pre> <p>I would expect mutableDeepCopy to return an object I own, so at some point I need to release or autorelease it. e.g.</p> <pre><code>NSMutableDeepCopy* temp = [self.immutableDictionary mutableDeepCopy]; self.mutableDictionary = temp; [temp release]; </code></pre> <p>or</p> <pre><code>self.mutableDictionary = [[self.immutableDictionary mutableDeepCopy] autorelease]; </code></pre> <p>So now we need to look at mutableDeepCopy. Because it has 'copy' in the name it needs to returned an "owned" object which, in practice means "forgetting" to release the returned object. You have already failed to do that when you create the returned object in the first line, since dictionaryWithCapacity: gives you an object you do not own. Replace it with </p> <pre><code>NSMutableDictionary *dictionaryToReturn = [[NSMutableDictionary alloc] initWithCapacity:[self count]]; </code></pre> <p>Now you own it.</p> <p>It is important that you make your mutableDeepCopy obey the rules because it means you can treat the objects returned from mutableDeepCopy, mutableCopy and copy in exactly the same way. In all three cases you own the object copy that you insert into the array. Because you own it, you must release it or it'll leak as you found out. So, at the end of the loop, you need</p> <pre><code>[copy release]; </code></pre> <p>That'll stop the leak.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload