8

Please help me track down an iOS memory leak. Thanks!

I'm using xCode 4.0.1 and I tried to activate NSZombie to track a memory leak, but it doesn't seems to work as before, with xCode 3.x

I can't find out where the memory leak is coming from, as Instruments points this out:

Leaked Object -> GeneralBlock-32 Address -> 0x4c8600 Size -> 32 Bytes Responsible Library -> libsystem_c.dylib Responsible Frame/Caller -> strup

At this point I don't know If I'm using Instruments with NSZombie the right way with xCode 4, as it doesn't show the NSZombie option when I click "i" for more information, under the left option Leaks.

OBSERVATION: My iPhone application plays a live stream mms/wma and also wma áudio files with a finite amount of time. The leak happens only with a finite wma file, but runs perfectly when I'm playing from a streamed source, with no ending time.

neowinston
  • 7,584
  • 10
  • 52
  • 83

2 Answers2

10

First, that is a malloc block, not an object. Zombies won't work (and would never have worked in prior versions either).

How many times does that leak happen? Once? Don't worry about it. Once per stream? file a bug -- that isn't in your code from what you have posted so far (unless your code is calling strdup, which is certainly possible but atypical in most iOS apps that aren't making heavy use of third party libraries... are you?)

In any case, unless it is leaking 100s and 100s of 32 byte allocations across the runtime of your app, don't worry about it (but please do file a bug).

As Valkio said, you can grab the stack trace of the allocation from gdb (or from Instruments) directly.

bbum
  • 162,346
  • 23
  • 271
  • 359
  • Thanks for your considerations, bbum. I'll file a bug report. And yes, I'm making heavy use of third party libraries: LibMMS (for parsing the audio stream) and FFMPeg (for decoding/playing) the WMA file. In this case, what should I look for? Because when I open a second stream, at end of the first stream, my app crashes when I manually stop the audio. I don't call strdup myself, unless the libraries I'm using is doing that. UPDATE: yes, LibMMS is calling strup when It makes the mms connection. – neowinston May 05 '11 at 15:48
  • A bug report probably won't do you much good if it is in a third party library. Sounds like a leak in that library. The crash is probably orthogonal (though it could boil down to a memory management issue in the library) and worthy of a different question. – bbum May 05 '11 at 17:38
5

You can see where it was allocated if you do this:

  1. Go to Product -> Edit Scheme -> Run (Debug) -> Arguments.
  2. Add this to environment variables: MallocStackLoggingNoCompact
  3. Set it to YES
  4. Run, and let it crash.
  5. type in console (gdb) info malloc 0x4c8600 or whatever the address is.
vakio
  • 3,134
  • 1
  • 22
  • 46
  • 2
    You can do this in Instruments, too. No need for gdb; click through the allocation's address in Instruments and it'll show the allocation stack trace. – bbum May 05 '11 at 15:24
  • Thanks for your answer, vakio. I did as you instructed me and in (gdb) when I typed info malloc 0x464890, it gave me this output: MyAppName (330) > What does this 330 means? – neowinston May 05 '11 at 15:38
  • Hm that's not right. You should get a malloc stack. Maybe instruments will work better in this case... – vakio May 05 '11 at 15:45
  • please, if you would, take a look at my response to bbum. thanks. – neowinston May 05 '11 at 15:59
  • I'm having the same problem except its leaking in 48 byte increments instead of 32 bytes. I'm using iOS 5.1 and the leak seems to be related to a UIScrollView scrolling with images. The leak doesn't seem big enough to worry too much, but still I'd like to know what I'm doing wrong. – Jackson Mar 19 '12 at 05:56
  • 1
    Did anybody solve this problem with little malloc leaks? I'm having it now, and when these errors pile up they crash my app... – Sylphos Nov 20 '12 at 19:14