Note that there are some explanatory texts on larger screens.

plurals
  1. PONSMutableArray causes memory buildup, not Autoreleasing with ARC
    text
    copied!<p>I created an array using the following code. After the 12 images have no longer needed, I set the imageArray to nil and reload a new set of images into this array. When I run the app in instruments I can see a memory buildup issue. I also ran heapshots and it shows 12 images still lingering even after I set the array to nil. I also tried to init this array in its own autorelease pool thinking it was somehow created on a separated thread below the main thread. That did not work either. Any ideas?</p> <p><strong>ViewController.h</strong></p> <pre><code>@property (strong, nonatomic) NSMutableArray *imageArray; </code></pre> <p><strong>ViewController.m</strong></p> <pre><code>- (void) firstSetOfImages{ imageArray= [[NSMutableArray alloc] initWithObjects:wordImage1, wordImage2, wordImage3, wordImage4, wordImage5, wordImage6, wordImage7, wordImage8, wordImage9, wordImage10, wordImage11, wordImage12, nil]; } - (void) clearImages{ [self setImageArray:nil]; [imageArray removeAllObjects]; [self secondSetOfImages]; } - (void) secondSetOfImages{ imageArray= [[NSMutableArray alloc] initWithObjects:wordImage1, wordImage2, wordImage3, wordImage4, wordImage5, wordImage6, wordImage7, wordImage8, wordImage9, wordImage10, wordImage11, wordImage12, nil]; } </code></pre> <p>Here is an example of 1 heapshot taken in between the loading of 1 set of 12 images and the second set of 12 images.</p> <pre><code>Snapshot Timestamp Heap Growth # Persistent Heapshot 3 00:39.457.174 53.02 KB 800 &lt; non-object &gt; 26.05 KB 277 UIImageView 3.38 KB 36 CFDictionary (mutable) 3.38 KB 72 CFBasicHash (key-store) 2.83 KB 73 CFBasicHash (value-store) 2.83 KB 73 NSPathStore2 2.25 KB 12 CGImageReadRef 1.88 KB 12 CALayer 1.69 KB 36 CGImage 1.62 KB 13 CFNumber 1.31 KB 84 CGImagePlus 1.31 KB 12 CFData 1.12 KB 24 CGImageProvider 768 Bytes 12 CGDataProvider 720 Bytes 5 UIImage 576 Bytes 12 CFString (immutable) 416 Bytes 13 CFArray (mutable-variable) 384 Bytes 12 CGImageReadSessionRef 192 Bytes 12 _ UIImageViewExtendedStorage 192 Bytes 4 __NSArrayM 160 Bytes 5 CFDictionary (immutable) 48 Bytes 1 </code></pre> <p>EDIT:</p> <p>I modified the code and made the arrays an ivar. I took another sample of Allocations in Instruments. Below are is a more detailed display of my heapshots. I took a heapshot every time I reset my array with 12 new images. Every heapshot is has a heapgrowth of about 35kb. </p> <pre><code>Snapshot Timestamp Heap Growth # Persistent Heapshot 4 00:58.581.296 35.63 KB 680 &lt; non-object &gt; 13.02 KB 220 CFDictionary (mutable) 3.38 KB 72 CFBasicHash (key-store) 2.81 KB 72 CFBasicHash (value-store) 2.81 KB 72 NSPathStore2 2.28 KB 12 CGImageReadRef 1.88 KB 12 CGImage 1.50 KB 12 CFNumber 1.31 KB 84 CGImagePlus 1.31 KB 12 CFData 1.12 KB 24 UIImageView 1.12 KB 12 CGImageProvider 768 Bytes 12 UIImage 576 Bytes 12 CALayer 576 Bytes 12 CFString (immutable) 384 Bytes 12 CFArray (mutable-variable) 384 Bytes 12 CGImageReadSessionRef 192 Bytes 12 CGDataProvider 144 Bytes 1 _UIImageViewExtendedStorage96 Bytes 2 __NSArrayM 32 Bytes 1 </code></pre> <p>Here is the stacktrace of one of those Persistent items in UIImage. It doesn't point to a specific line of code that created it. Not sure where to go from here?</p> <pre><code> 24 FourGameCenter 0x4b4bf 23 FourGameCenter 0x4b538 22 UIKit UIApplicationMain 21 GraphicsServices GSEventRunModal 20 CoreFoundation CFRunLoopRunInMode 19 CoreFoundation CFRunLoopRunSpecific 18 CoreFoundation __CFRunLoopRun 17 CoreFoundation __CFRunLoopDoSource1 16 CoreFoundation __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ 15 GraphicsServices PurpleEventCallback 14 GraphicsServices _PurpleEventCallback 13 UIKit _UIApplicationHandleEvent 12 UIKit -[UIApplication sendEvent:] 11 UIKit -[UIWindow _sendTouchesForEvent:] 10 UIKit -[UIControl touchesEnded:withEvent:] 9 UIKit -[UIControl(Internal) _sendActionsForEvents:withEvent:] 8 UIKit -[UIControl sendAction:to:forEvent:] 7 UIKit -[UIApplication sendAction:toTarget:fromSender:forEvent:] 6 UIKit -[UIApplication sendAction:to:from:forEvent:] 5 FourGameCenter 0x8d7fa 4 FourGameCenter 0x71830 3 FourGameCenter 0x797e6 2 libobjc.A.dylib _objc_rootAllocWithZone 1 libobjc.A.dylib class_createInstance 0 libsystem_c.dylib calloc </code></pre>
 

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