New empty iOS app has dozens of memory leaks
Asked Answered
N

1

7

Using the Leaks Instruments tool on a new, from-scratch, one-view iOS app reports 23 leaks. This doesn't seem right — am I missing something? Repeated runs yield different leak counts, from 16 to 35. Steps to reproduce follow this screenshot.

A similar, unanswered question, was posted at Memory leak in login with amazon sample ios app

Screenshot of Instruments window

I'm using Xcode 10.2.1 (10E1001); iOS 12.2 (Simulator & device both show leaks, with or without Reveal activated.)

  1. Create fresh one-view iOS app.
  2. In Scheme > Run/Debug section, enable
    • Memory Management > Malloc Scribble
    • Logging > Malloc Stack (Live Allocations Only)
  3. Run Product > Profile (⌘I)
  4. First leak check is green; wait for second one.
  5. Twenty-three new leaks! (As shown above.)

However, apart from Instruments, Debug Navigator disagrees:

  1. Run normal debug session
  2. Click "Debug Memory Graph" at top of Debug area.
  3. Debug Navigator (below) has no purple exclamation marks (leak alerts).

Screenshot of Debug Navigator

Numerable answered 16/5, 2019 at 18:7 Comment(4)
Did you look at the leaked objects? I believe there are multiple small leaks in the standard frameworks, maybe some of them are not actually leaks. Leak detection is not so simple.Curiosity
I noted above that device also shows leaks. (58 last time I checked!) The "Responsible Library" column lists just Foundation and UIKitCore. I've exported the memgraph and used heap and malloc_history and leaks but am still a bit baffled.Numerable
Thanks for posting this. I did the same thing with any empty project my was called MemoryLeaks. I got the same result. It's good to know this before spending hours trying to eliminate all leaks from our projects.Narcose
Yeah, esp. when the online video demos show the little green checkmarks marching across the screen. You wonder "how did they do that?" One worries that ignoring the red ones is like asking for another Chernobyl...Numerable
L
4

The release notes for Xcode 10.3 say:

Resolved an issue where running an app in iOS 12.2 or later under the Leaks instrument resulted in random numbers of false-positive leaks for every leak check after the first one in a given run

That sounds exactly like this issue. So it was a bug (a Heisenbug?), and now it’s fixed.

Lathery answered 24/7, 2019 at 2:15 Comment(3)
Verified. Quite a bug, rendered useless an important tool. Thanks Matt!Numerable
Sorry you had to suffer through this bug, but you did describe it awfully well, so that I recognized at once that it resembled the sentence in the release notes. — As a side note I may mention that there have always been false-positive leak reporting bugs of one sort or another; it's just that this one was particularly acute.Lathery
Been trying to solve this for hours now, thank god I saw this post!Minutia

© 2022 - 2025 — McMap. All rights reserved.