Is it normal that my cocos2d app increase real memory usage every second?

China☆狼群 提交于 2019-12-13 01:27:33

问题


I develop cocos2d iOS app for iPad. When I test memory leaks and object allocation my Live Bytes are stable, but when I run Activity Monitor I see that the Real Memory Usage of my app increase every second with 0.02MB.

I want to ask is it normal and did someone have similar problems?


回答1:


This is entirely plausible, because Cocos2d (at least the 0.9.x and 1.0 branches) tends to autorelease everything. This can lead to memory build up on situations where you're spawning a lot of sprites onscreen in a loop. If you're indeed autoreleasing and not leaking, adding an autorelease pool along with your loop may be a quick fix. That said, you might actually be leaking.

To debug memory leaks, I'd start with the Leaks Instrument and perhaps the Allocations instrument as well. In Xcode, hit Command + I, or Product -> Profile

Once you've got the profiler open, you'll see a menu which contains a bunch of debugging instruments:

Once you select leaks, you'll see this handy windows with all kinds of useful information:

On top, you'll see memory allocations and leaks as a graph. On the bottom you can see all kinds of useful information, such as what objects are allocated, how much memory is in use, and a lot more.

For a full treatment of Xcode debugging with instruments, check out this handy Apple Developer video (login required).




回答2:


A year later and I had this exact question. Turned out, I had zombies enabled and that was responsible for my increase in memory every second.




回答3:


I remember that I have this problem because I log debug messages!

I logging this messages in loop cycles (every frame) and this was the reason why the memory increasing!

Please clear or comment all log messages, this will slove your problem :)



来源:https://stackoverflow.com/questions/13231570/is-it-normal-that-my-cocos2d-app-increase-real-memory-usage-every-second

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