Note that there are some explanatory texts on larger screens.

plurals
  1. POiPhone Instruments Leaks is confusing me. UIView fade out animation causes a lot of tiny leaks
    text
    copied!<p>I'm trying to kill all memory leaks in my iPhone 3.0 application. CLANG builds with all lights green so now I'm analyzing with Instruments. </p> <p>This is easier said then done, since it is indicating hundreds of 16 byte leaks after just a few minutes of using the app. It seams to be mainly in UIKit, and the common part is that the end of the stack trace always calls <code>[NSObject respondsToSelector]</code></p> <p>Is this something I can ignore or what can be the reason for all these leaks? I I can ignore them, is there a way to filter them out in Instruments, so I can detect the real leaks?</p> <p>*EDIT I managed to find the part of my code that caused the problem, but I still don't understand why. I have a custom UIView with some text and a spinner that is visible during an async http request. When the request is done I call this method on the view:</p> <pre><code>- (void)fadeOut{ spinner.hidden = YES; loadingLabel.hidden = YES; messageLabel.hidden = YES; [UIView beginAnimations:nil context:nil]; [UIView setAnimationDelegate:self]; [UIView setAnimationDidStopSelector:@selector(fadeComplete)]; [UIView setAnimationDuration:0.40]; self.alpha = 0.0; [UIView commitAnimations]; } - (void)fadeComplete{ [self removeFromSuperview]; } </code></pre> <p>If I instead simply do</p> <p><code>[self removeFromSuperView]</code> without the alpha animation, there is no leaks reported.</p> <p>See the screenshot below for Instruments details.</p> <p><a href="http://img.skitch.com/20091123-kr98nky7nqdeuqjm4n9khbug9j.png" rel="nofollow noreferrer">Instruments Screenshot</a></p> <p>A sample stack trace:</p> <pre><code> 0 libobjc.A.dylib _malloc_internal 1 libobjc.A.dylib _cache_addForwardEntry 2 libobjc.A.dylib lookUpMethod 3 libobjc.A.dylib class_respondsToSelector 4 CoreFoundation -[NSObject respondsToSelector:] 5 UIKit -[UINavigationTransitionView transition:fromView:toView:] 6 UIKit -[UINavigationTransitionView transition:toView:] 7 UIKit -[UINavigationController _startTransition:fromViewController:toViewController:] 8 UIKit -[UINavigationController _startDeferredTransitionIfNeeded] 9 UIKit -[UINavigationController viewWillLayoutSubviews] 10 UIKit -[UILayoutContainerView layoutSubviews] 11 UIKit -[UIView(CALayerDelegate) _layoutSublayersOfLayer:] 12 QuartzCore -[CALayer layoutSublayers] 13 QuartzCore CALayerLayoutIfNeeded 14 QuartzCore CA::Context::commit_transaction(CA::Transaction*) 15 QuartzCore CA::Transaction::commit() 16 QuartzCore CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) 17 CoreFoundation __CFRunLoopDoObservers 18 CoreFoundation CFRunLoopRunSpecific 19 CoreFoundation CFRunLoopRunInMode 20 GraphicsServices GSEventRunModal 21 GraphicsServices GSEventRun 22 UIKit -[UIApplication _run] 23 UIKit UIApplicationMain 24 Client main **/main.m:14 25 Client start </code></pre> <p>And another one:</p> <pre><code> 0 libobjc.A.dylib _malloc_internal 1 libobjc.A.dylib _cache_addForwardEntry 2 libobjc.A.dylib lookUpMethod 3 libobjc.A.dylib class_respondsToSelector 4 CoreFoundation -[NSObject respondsToSelector:] 5 UIKit -[UIViewAnimationState animationDidStart:] 6 QuartzCore run_animation_callbacks(double, void*) 7 QuartzCore CA::timer_callback(__CFRunLoopTimer*, void*) 8 CoreFoundation CFRunLoopRunSpecific 9 CoreFoundation CFRunLoopRunInMode 10 GraphicsServices GSEventRunModal 11 GraphicsServices GSEventRun 12 UIKit -[UIApplication _run] 13 UIKit UIApplicationMain 14 Client main ***/main.m:14 15 Client start </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