Xcode Memory Graph - showing increasing memory use - what exactly does it show?

戏子无情 提交于 2019-12-05 02:48:53

问题


When watching the debug graph in xcode 6 (and probably 5 too), when running my application the memory use continues to rise as I place more of a certain object on the screen and animate it's movement. It does not seem to decrease when I remove it. Once removed I believe there are no more references to them.

See screenshot: http://i.stack.imgur.com/SnhbK.png

However when I use Instruments to try to identify what's going on, there's only around 12mb persisting, and Total Bytes continues to rise, as expected.

See screenshot: http://i.stack.imgur.com/VBwce.png

Is this normal behaviour? What exactly is the graph in Xcode showing? Am I overlooking something?

In Instruments I have Allocation Lifespan set to All Allocations and Allocation Type set to All Heap and Anonymous VM for the screenshots above.

UPDATE

By running Instruments with Activity Monitor I was able to see that the "Real Memory" was increasing at the same rate as is displayed in Xcode. @Mark Szymczyk pointed out that OpenGL ES Texture memory allocations are not shown in the Allocations instrument.

By purging the texture cache with the following command in Cocos2D 3.1 at regular intervals, memory use consistently drops back down to around 18mb and begins increasing again as I add more sprites.

[[CCDirector sharedDirector] purgeCachedData];

Credits go to Mark Szymczyk for pointing me in this direction - thanks!


回答1:


Looking at your screenshots, the Xcode graph is probably showing the equivalent of the Total Bytes column in your Instruments screenshot. When you remove an object, the persistent bytes will decrease, but the total bytes won't. That would explain why the memory use never goes down in the Xcode graph.

The Persistent Bytes column in Instruments is what you should be looking at to determine your app's memory usage.



来源:https://stackoverflow.com/questions/26273361/xcode-memory-graph-showing-increasing-memory-use-what-exactly-does-it-show

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!