views:

36

answers:

1

Hey all, I have a problem and I'd like some advice.

I'm working on a document viewer that's composed of the following major parts:

  1. zip library which unpacks the document container (minizip)
  2. xml library which parses the document (libxml2)
  3. UI code which renders the document on screen

Nothing too complicated or fancy.

On the emulator, everything works beautifully; the viewer performs as expected. I've ran it through Instruments and there are no leaks. ObjectAlloc reports about 5.5 megs allocated over the lifetime of the viewer (that's repeatedly opening my test document over and over).

Unfortunately on the device (iphone 3G, iOS 3.1.2) things aren't as clear. Fairly frequently, repeated opening of the test file causes an out of memory error and the file will fail to open. Initial file opening always works. Even though emulator testing highlighted no leaks and the overall memory footprint was modest, I'm forced to conclude that there IS indeed a leak on the iphone (because why would repeated opening cause out of memory error).

I've attempted to run instruments on the device, but the app stalls (?!) half way through the run, so I actually had no success running Leaks.

I believe that there's a significant leak somewhere that only shows up on the device. So, I'm left with a two options (in no particular order):

  • Refactor my code in such a way as to avoid using zip library. That would eliminate a potential source of leaks. Time consuming and inconclusive.
  • Reformat and reinstall everything on my phone (maybe there's something that's causing a problem there). Pretty much as above, time consuming and sucks losing my phone data. Maybe it'll let me run Leaks though.

As you can see, I'm reaching here. Is there anything obvious that I'm missing?

Thanks in advance guys.

+1  A: 

Maybe, you should try to run not Leaks, but Allocations Instrument on your device, and to search leaks with it (manually)?

+ (maybe this sounds stupid) Remove app from the device and repeat Clean-Build-Run with Leaks (why not?).


About manual leaks search.

Just start the Allocations Instrument and, while using your app, do every action for several times (for example - press button twice or more; navigate to some panel and back for several times - and so on). Memory should increase significantly only once or increase on action start and decrease on action end (of course, some divergences are possible, but they should be reflected with small amounts of memory). You will see it on graph.

Also make heaps (in Instruments' left panel while Allocations Instrument is selected there is a button for this) - they will help you to detect "still alive" objects that were considered as destroyed (there will be a lot of objects, but the first and easiest step is to check objects of your own classes).

kpower
Do you mean "ObjectAlloc"? And what do you mean by searching for them manually? Thanks for the suggestions!
EightyEight
Hmm, I think so. But in my Instruments (in instruments selection menu) and in my XCode (Main Menu: Run -> Run with Perfomance Tool) it is called "Allocations".And about manual search - see my answer (I edited it to add details).
kpower