Вопрос

I've been using Instruments on an ARC project (run on a device) to make sure I'm cleaning up any abandoned memory. To this end, I've been using the allocations generations tool and taking snapshots of my heap for the same action 10-20 times. What I'm confused about is the growth. Some of the time the growth is 0, and then the other, some number of bytes (never consistent ranging from a few bytes to a several kilobytes) seems to be accruing. But there is usually at least few iterations where the growth is 0.

My question is: if my growth is sometimes 0, does that mean that my memory management is correct? Or do I still have issues that I need to ferret out? I understand that it might take several cycles for the memory to "drain", but what about the memory that is still being allocated and remaining even after >10 iterations?

This seems like a more general question about the interpretation of Instruments, so I've left out any specific code. Besides, I've found this happening in various heap snapshot scenarios: pull to refresh, push view controller, etc.

Edit: I've included a snapshot of my Instruments window.

Это было полезно?

Решение

I would say that if you have several iterations of your action loop that result in 0 bytes allocated and still living then you are good on memory management and have no leaks.

The increases you are seeing (from a few bytes to a few kilobytes) are most likely from the OS or background Apple code doing things to try to manage the tasks you are doing. One easy example is if you bring up the keyboard for the first time Apple allocats memory for it that is never released, so that iteration you will see "leaked" memory that you didn't create. Everything you do has background code that Apple runs and you can't define what it wants to do with memory. It could be cacheing specific things that are done often so that next time it runs faster. The whole Apple philosophy is smooth running apps so the user experience is the best it can be. What the OS does in the background to make that happen can be intermittent and can cause unreleased memory.

Check the heap-snapshots for what objects were allocated and not released. If you can track those objects to your code then fix it, if you can't then it's likely an OS allocation that either can or cannot be avoided. Like I said a moment ago, if you are getting a lot of 0 increases then I would not worry about it because of these intermittent OS increases.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top