Apple's Sample App TopSongs has 26 Leaks

2019-07-26 17:01发布

问题:

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.

回答1:

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/



回答2:

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.



回答3:

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.



回答4:

Installed Snow Leopard and Xcode 3.2 with built-in clang. Analyzed the code and had no issues. I ran the app again leaks instrument on the iPhone and still had 26 leaks. Decided not to use Apple's sample code for this.

*******NOTE:

This WAS the answer I accepted, but because it doesn't ANSWER the questions, I removed it and accepted a response that answers the question.