views:

946

answers:

4

Hi

When I run my app with Leaks and view the Extended Details for any of the leaks, it takes me to a particular line in my code, but I don't know what to do after that!

For instance, Leaks shows a malloc at this line

NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];

But I do not know what the problem is in the statement! Can someone please tell me how to interpret such problems and avoid leaks.

Thanks.

Edit: Regarding the previous question I had, NSZombieEnabled makes sure no objects are deallocated and this increases the memory usage. So when testing with Leaks, make sure this setting is removed from your app. Thought this might help someone.

+1  A: 

The Extended Detail pane will give you stack traces showing you the stack at the leak. Generally a good place to start is to look at your methods & the last method of your code in the stack and see what you are doing memory wise there, it sounds like you could be over retaining an object. Start there for now

Colin Wheeler
Hi Colin. The Extended Details pane does not show the class or method which is causing leaks in case of zombie objects. Thats the reason I posted the question. How do I know where the zombie objects are created? Thanks.
lostInTransit
Can you show a screenshot of what you see? Also what iPhone OS Version are you targeting?
Colin Wheeler
+1  A: 

Do you free the response and error objects after the call? Those are possibly allocated in the call.

Fredrik Jansson
Hi Fredrik. If I release the response and error objects, it shows a malloc at that location, again a leak! I will post some more code and the logs when I get back to my mac. Thanks.
lostInTransit
+1  A: 

A leak in the method you mention above was supposed to be fixed for the iPhone OS 2.2 release. Which version of the iPhone OS are you using?

Eric Albert
I'm using 2.1. Created the project before 2.2 was released. Are you sure this was fixed with 2.2? Thanks
lostInTransit
+3  A: 

Found the answer. Fredrik's response got me thinking. I was creating an instance of NSURLResponse and NSError which I was then passing to the sendSynchronousRequest method. According to the memory management document of the iPhone, this should not be done. We just need to pass a reference to the NSURLResponse and NSError objects to the method and the method takes care of creating and releasing the objects.

Hope that helps someone else. Thanks a lot for the answers everyone.

lostInTransit