I'm running leaks through Instruments on my iPhone app and I'm seeing a lot of leaks that don't appear to be coming from my code.
For example:
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request
delegate:operation];
operation.urlConnection = connection;
[connection release];
Leaks is telling me that the first line is leaking 1008 bytes. That seems to be a pretty standard alloc init with a release. Other leaks that are mentioned are in UIKit and WebKit.
Is it possible that these leaks are in fact in Apple's frameworks, or is more开发者_StackOverflow likely my code and leaks isn't showing the information accurately?
It's entirely possible that Apple's frameworks have leaks in them (however unlikely it may seem) - there were several in the Core Data implementation for iPhone in the 3.0 GM release.
What you should do when you suspect such a thing is try to find a sample project from Apple that uses the functionality you're looking at or reduce your own code as much as possible (maybe build a minimal side project), then test that with Instruments. If you can reproduce the leak reliably, submit a bug to Apple.
Are you running with NSZombieEnabled
? That will cause fake "leaks" to show up in Instruments.
I think this is where your leak stems:
operation.urlConnection = connection;
You may not be doing proper memory management in operation
.
Besides that, have you tried to test the app on device instead of simulator? Running instruments on simulator is not very accurate and reliable. Try this one as well http://www.tuaw.com/2009/09/08/xcode-3-2-daily-tip-analyzing-your-code/
Do you keep a reference to your delegate object anywhere else?
If you think about it, Leaks would assume delegate is a leak if you have no other references to it around but it is still retained. Also, how are you freeing your delegate (named operation) when the request is done?
精彩评论