views:

50

answers:

2

Hi everyone

I have an, at least to me, strange case here: I have a relatively simple program which loads an XML file from the web, parses it and write the data into an array of dictionaries. Each dictionary represents a row in the table. The program works fine and if I attach my simulator to instruments and load the list, there is no memory leak.

Now here is the strange part: There is a button for the user to reload the list. If you press it, the previous data gets cleared, the XML newly downloaded and parsed and so on. If I press this button, I still can't find a memory leak. Yet if I press it twice, suddenly there are leaks all around. I am very puzzled, how come there are suddenly leaks where there used to be none before (The leaks only appear if the same code is run twice)? It is especially weird as I am using part of Apple's sample XMLParser for instance, my code is a 1:1 copy of theirs, yet when I run the parser twice, instruments reports a leak in this code.

I am glad for any help, I pretty much don't know how to got about this. The code should be fine. I have already tried "Build and Analyze", it does not reveil anything I would not see in instruments either.

All the best, Robin

A: 

The program works fine and if I attach my simulator to instruments and load the list, there is no memory leak.

That doesn't mean you have no leaks - instruments may not be catching them - it samples every n/seconds.

Mr-sk
+1  A: 

There really isn't enough info here to make a solid answer.

That said, it sounds like you could be misinterpreting the results of the memory leak detection tool that you're using. If it is scanning the object graph looking for orphaned objects, it may not notice that an object is orphaned until you re-load. That's because there may be a static, cached reference to the root of the object graph in one of the 3rd-party libraries you're using (or in your own code.) Once you re-load, the cached reference is moved to the new root object and all the old objects are no longer referenced by any rooted variables (local variables on the call stack or static variables) and are therefore orphaned and "leaked".

David Gladfelter
Thanks a lot, this sounds very interesting. I fully understand that you can not give a detailed solution as long as you have no code, but is there any way to detect whether such cached objects are used or not (eg. is there a possibility to turn this caching of?) Thank you very much for your input!
Robin