Search code examples
objective-ciosmemory-managementmemory-leaksinstruments

Analyze and instruments


Well, that question may sound silly, but... When I run my app in analyze mode or with instruments I get no possible (analyze mode) or memory (instruments) leaks. Does it mean that my app is 100% memory leaks free ?


Solution

  • No. For one thing, you'd have to run every possible execution path/state sequence in your app to definitively say that there are no leaks by simple testing. More importantly, true memory leaks, where you don't release memory but no longer have a reference to it are all the leaks instrument is able to detect.

    However, those are not the only similar problem you can create. You can also easily not discard data that you no longer actually need, causing memory to build up. This isn't a true leak, as you still have a reference to the data in question, it's just that you haven't released it and gotten rid of your reference to it.

    You can still find this kind of problem using the allocations instrument. It won't explicitly flag problems, but it will allow you to see if you're allocating lots of memory that you don't later release. On iOS in particular, it's important to make sure that you give up allocated memory when you no longer need it, or your app's memory usage will grow until the OS terminates your app.