views:

326

answers:

5

Hey all, I've been building an app for a client and part of it uses Apple's TopSongs sample app to download data on another thread. I finally got enough done to start testing that part and found >1000 leaks!!! A closer look at the leaks made me check TopSongs for leaks, since none of the my methods were in leaks report. Running TopSongs returned 26 leaks. Not quite sure how to fix them, or if they are part of some library from Apple.

I bet you're asking if it has 26, why do you have >1000? Well, I use their sample to make roughly 48 calls to webservices to get all the information needed on initial install (48 calls x 26 leaks = 1248 leaks!!). Later it makes at least 12 calls + 4 to check for updated information on other sections of the app. Can't do a thing about it, can't make one call, or less calls, please don't comment about this part. I seen people respond to posts that aren't necessarily answering the question the user originally posted, which in this case is has anyone tried patching up the leaks, if they are patchable, or is this a bug in Apple's libraries?

Thanks so much.

+6  A: 

This is more likely due to a bug in sloppy sample code than the library itself; make sure to acquaint yourself properly with Cocoa memory management techniques, and then strap yourself in for wabbit hunting season.

Williham Totland
lol..................
Rev316
LMAO! Yeah, been there done that. Hate having to **check** their code. But if it's gotta be done, it's gotta be done! one-up for the funny answer!
RoLYroLLs
A: 

I'm trying to see if I can find some leaks myself in Apple's TopSongs app. Can someone help me out in at least one and how to identify what is in the Leaks reports and how I can get an idea on finding them?

ie: I got one like this:

#    Category    Event Type  Timestamp   Address Size    Responsible Library Responsible Caller
0   GeneralBlock-448    Malloc  00:02.185   0x3f41220   448 libxml2.2.dylib xmlNewParserCtxt

From what I can tell, the method xmlNewParserCtxt is the problem, and it's not releasing an object, hence Malloc. The responsible library tells me it's the libxml2.2.dylib library with the problem, which I can't edit.

Am I heading in the right direction? If so, half the leaks are in that library and well, i can't edit that.

RoLYroLLs
BTW: for future reference, should I have updated my initial question and added this to it, or is it fine putting it as an answer? Thanks
RoLYroLLs
You should have updated your initial question and added this to it.
Lawrence Johnston
+1  A: 

As stated before on Stack Overflow, some reported leaks only happen in the simulator. So look out for that, and use "build and analyse" in the build menu to let CLANG help you find the memory leaks.

bartvdpoel
I don't have Build and Analyze. I started this project before trying to upgrade to Snow Leopard. I have Leopard 10.5.8 w/ Xcode 3.1.4 and iPhone SDK 3.1.2. As soon as I'm done I will be upgrading though.
RoLYroLLs
@RoLYroLLs: You can still manually install the Clang Static Analyzer from outside Xcode to use it on Leopard: http://clang-analyzer.llvm.org/
Brad Larson
Believe me, if you're used to it, you can't live without it anymore...
bartvdpoel
Cool thanks! I'll try it out
RoLYroLLs
@bartvdpoel: I finally got Snow Leopard, ran leaks while on the iPhone and still had 26 leaks. Definately a problem with their library, as clang found no issues with the code itself.
RoLYroLLs
A: 
RoLYroLLs
+1  A: 

You can find the fixed version of the TopSongs here: http://www.bigbluebrains.com/index.php/2010/08/16/iphone-topsongs-sample-code-memory-leak-fix/

Fady Younan