devguydavid
devguydavid

Reputation: 4149

iPhone memory leak

I know that there are memory leaks that are no big deal or are out of the individual developer's control as they are in the sdk itself, but the one I'm seeing is 32KB on the iPhone 4 build against iOS SDK 4.2. I have not been able to trigger this on a 3GS. It happens in response to user interaction (in response to opening the photo library, and the leak seems to happen while I'm in the photo library), so it could build up quickly.

Here's the stack trace I'm seeing on the iPhone 4:

   0 libSystem.B.dylib calloc
   1  0x317e8363
   2  0x317e9c41
   3  0x318273ff
   4  0x31827ea5
   5  0x302ea49d
   6  0x302ebe07
   7  0x302eb7c3
   8  0x302ebcab
   9  0x303304cd
  10 UIKit -[UINavigationController _startTransition:fromViewController:toViewController:]
  11 UIKit -[UINavigationController _startDeferredTransitionIfNeeded]
  12 UIKit -[UINavigationController viewWillLayoutSubviews]
  13 UIKit -[UILayoutContainerView layoutSubviews]
  14 UIKit -[UIView(CALayerDelegate) layoutSublayersOfLayer:]
  15 CoreFoundation -[NSObject(NSObject) performSelector:withObject:]
  16 QuartzCore -[CALayer layoutSublayers]
  17 QuartzCore CALayerLayoutIfNeeded
  18 QuartzCore CA::Context::commit_transaction(CA::Transaction*)
  19 QuartzCore CA::Transaction::commit()
  20 QuartzCore CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*)
  21 CoreFoundation __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__
  22 CoreFoundation __CFRunLoopDoObservers
  23 CoreFoundation __CFRunLoopRun
  24 CoreFoundation CFRunLoopRunSpecific
  25 CoreFoundation CFRunLoopRunInMode
  26 GraphicsServices GSEventRunModal
  27 GraphicsServices GSEventRun
  28 UIKit -[UIApplication _run]
  29 UIKit UIApplicationMain
  30 MyApp main /Users/david/src/MyApp/main.m:14
  31 MyApp start

I don't see my code anywhere here and I'm not sure what to do to inspect the symbols with addresses. Any ideas? Could this have something to do with the sublayers I'm adding? (That's the only thing I see here that I might have control over.)

Thanks for any help.

Edit: As GojaN's question points out (Thanks, GojaN), I completely forgot to mention that this is showing up in instruments as:

Leaked Object # Address Size Responsible Library Responsible Frame
GeneralBlock-36864   0x4ff3000 36864 UIKit -[UINavigationController _startTransition:fromViewController:toViewController:]

Upvotes: 1

Views: 1724

Answers (3)

devguydavid
devguydavid

Reputation: 4149

Shortly after this my phone started acting very strangely. I deleted my app, reinstalled it, and haven't been able to get this to happen again. Since it was rather consistent before and easy to reproduce, I'm going to have to chalk it up to straight wonkiness.

Thank you to those who offered advice.

Upvotes: -1

Moshe
Moshe

Reputation: 58087

You should look into the "Build and Analyze" option from the Xcode "Build" menu.it will show you where your code might leak, from a compile time perspective.

Upvotes: 1

David Dunham
David Dunham

Reputation: 8329

Do you know it's a leak? It's quite possible it's a cache. (Semi-related: I saw memory keep growing in my PDF viewing app, which looked like a leak. But it was apparently caching each page, and they all went away when I closed the PDF doc.)

Leaks usually happen in Simulator as well as device, does it happen there?

This is code running in the run loop but likely initiated by your code. So does this block get leaked every time you run your code?

Upvotes: 1

Related Questions