English 中文(简体)
memory leaks appearing after multiple loading
原标题:

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

最佳回答

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".

问题回答

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.





相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签