0

I have been struggling with this one for whole morning. not being able to test on devices yet, i rely on what profiler shows only to roughly see there are no major issues. One of which I consider as serious is the fact that whenever I create 2D texture either in Cocos2d or in custom code - directly supplying openGL, I have in profiler all my textures are displayed as two allocations.

E.g. when I create a texture 512x512x4 which is roughly 1MB of data, my live bytes usage jumps by 2MB and I can see in list of live objects two heavy blocks of memory 1Mb each - exactly as my texture.

And let me stress that point - this is NOT a raw image file I supplied to the glTexImage2D(), which gets deleted in the destructor and I have checked it many times. Also the problem I observed also in Cocos2d example projects - simple all the memory for textures is doubled.

below two screeshots - one from cocos2d app , shows two textures 600KB each displayed in the profiler as FOUR allocated objects : enter image description here

and custom allocated and created texture directly with openGL and image supplied via libpng - displayed as live two objects 1Mb each. enter image description here

I would appreciate if anyone could enlighten me on this one. Perhaps in the device situation looks different.

Regards, s.

4

1 回答 1

1

这是 cocos2d 中的正常行为。它首先将图像文件加载为 UIImage,然后将其转换为 CCTexture2D。这意味着在大多数情况下,内存使用量是您预期的两倍。下一帧应该释放额外的内存。

您可以在我的内存优化博客文章中找到有关此行为的更多信息。您还将了解到,使用 .pvr.ccz 不仅会显着减少内存开销,而且它们的加载速度也会比 PNG 快得多(更不用说在 cocos2d 中加载速度非常慢的 JPG)。

于 2013-01-14T20:32:24.443 回答