Is it normal that my cocos2d app increase real mem

2019-07-28 17:54发布

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?

3条回答
冷血范
2楼-- · 2019-07-28 18:17

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

Xcode build menu

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

Instruments selection menu

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

enter image description here

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).

查看更多
贼婆χ
3楼-- · 2019-07-28 18:18

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 :)

查看更多
男人必须洒脱
4楼-- · 2019-07-28 18:21

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.

查看更多
登录 后发表回答