Taken 40M memory for loading 2 piece of 2048*2048 pngs ?

Forums Programming cocos2d support (graphics engine) Taken 40M memory for loading 2 piece of 2048*2048 pngs ?

This topic contains 9 replies, has 7 voices, and was last updated by  Martin 2 years, 4 months ago.

Viewing 10 posts - 1 through 10 (of 10 total)
Author Posts
Author Posts
November 27, 2011 at 2:45 am #237230

ltby_sky
@ltby_sky

I combine lot of magic effect frames into 2 big images (2048*2048), and taken more than 40M memory for loading them into memory by using CCSpriteFrameCache, anyone have this problem ?

Or you can just simply try with it:

[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile: @”magicAtlas1.plist”];

[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile: @”magicAtlas2.plist”];

magicAtlas1.plist:

http://www.mediafire.com/?q5haj6zcy4aljnf

magicAtlas1.png:

http://www.mediafire.com/i/?d3al4ik74cx12mg

magicAtlas2.plist:

http://www.mediafire.com/?kho4jtdyuxixpt6

magicAtlas2.png:

http://www.mediafire.com/i/?9rrr67ewts4u5yn

November 27, 2011 at 4:20 am #356496

CJ
Moderator
@wiseganesha

One image at 2048×2048 RGBA8888 (32bits per pixel) will take 16MB of memory, so two will be 32MB.

November 27, 2011 at 4:44 am #356497

ltby_sky
@ltby_sky

I found someone had the same problem, he said:

originally I kept both image data and texture data, and now I release both after upload it to OpenGL.

As a result I save 50+ MB system memory

How do I release the data in Cocos2D as he said ?

http://forums.indiegamer.com/showthread.php?9853-Texture-memory-usage-using-OpenGL

November 27, 2011 at 4:55 pm #356498

araker
Moderator
@araker

Cocos already frees all buffers that are needed to create the texture. Take a look at the

- (id) initWithImage:(UIImage *)uiImage resolutionType:(ccResolutionType)resolution method of CCTexture2D and you’ll see that the buffers used are being freed as well.

You can use the allocations instrument to see what takes up the 8 Mb you can’t account for.

November 27, 2011 at 6:03 pm #356499

riq
Keymaster
@admin

Important: there is a bug on iOS 4 and iOS 5 (and possibly on iOS 3 and iOS 2) that allocates 33% more memory for the textures.

So if you are creating two 2048×2048 32-bit textures, in theory it should allocate 32Mb, but in practice it will allocate 42Mb.

Mipmap textures need 33% more memory, but iOS allocates 33% more memory whether or not the textures have mipmap information. This is a nasty bug.

More info:

https://devforums.apple.com/thread/113889?tstart=0

This bug affects all OpenGL games (including cocos2d games)

November 27, 2011 at 6:19 pm #356500

slembcke
Administrator
@slembcke

Huh. Never looked close enough at memory usage to notice that. I guess I might as well be enabling mipmapping all the time instead of trying to save memory. Heh.

November 27, 2011 at 6:50 pm #356501

ltby_sky
@ltby_sky

Thanks for reply, I have reduce the image size for free some memory.

But I got another problem with releasing the animation frames image when they are no longer useful.

I can see the memory free when I remove the texture created by CCSprite.initWithFile,

CCTextureCache.removeTextureForKey

But it wont work with the texture created by [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@”xxx.plist”];

November 28, 2011 at 2:07 am #356502

Martin
Participant
@martinh

Since those are animations I think you’ll get away with a lot less color information in the textures. Check out http://www.texturepacker.com/ and try to save your animations as RGBA4444 with dithering enabled.

Also thanks @riq for pointing that bug out. Makes it a lot easier to plan my resources for textures.

November 28, 2011 at 4:56 pm #356503

JC
@jc

> But it wont work with the texture created by [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@”xxx.plist”];

it’s normal, because the sprite frame cache keep handle to the texture.

but you can remove all your sprite from the cache using [[CCSpriteFrameCache sharedSpriteFrameCache] removeSpriteFramesFromFile:@”xxx.plist”];

and after remove the texture using [[CCTextureCache sharedTextureCache] removeTextureForKey:@”xxx.png”];

November 28, 2011 at 5:41 pm #356504

Martin
Participant
@martinh

I have somewhat releated question: can I force bitmap font textures that are created with glyph designer into another texture format when loading them?

E.g. when I set the default texture format to RGBA4444, and load the texture into the texturecache with:

[[CCTextureCache sharedTextureCache] addImage:@"image-File-name.png"];

(and then set the default texture format back to RGBA8888)

When I then create a bitmap font label with a font file that uses this texture, will it automatically load the correct texture instead of creating a new one in RGBA8888 mode?

Viewing 10 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic.