Will JPG cause higher memory usage spike in cocos2d-x?

Hello, our project is using some big textures (1024*2048), and they are in JPG formats ( we can use other formats of course, but I still want to know the answer to my question ).

According to this link: http://www.learn-cocos2d.com/2012/11/optimize-memory-usage-bundle-size-cocos2d-app/ , it says:

“Cocos2d-iphone has a problem with JPG textures. There’s been a “temporary fix” (temporary for years) in the JPG texture loading routine that causes the JPG to be converted to PNG on the fly. That means cocos2d-iphone loads JPGs extremely slowly as you can see here and a JPG will use three times as much memory while the image is being loaded."

I checked the code of cocos2d-x, it seems that both png and jpg will in the end be inited by [UIImage imageWithData]. however, I also find a function below:

static bool *initWithFile
{
CGImageRef CGImage;
UIImage jpg;
UIImage
png;
bool ret;
// convert jpg to png before loading the texture
NSString *fullPath = ;
jpg = initWithContentsOfFile: fullPath];
png = initWithData:UIImagePNGRepresentation];
CGImage = png.CGImage;
ret =*initWithImage(CGImage, pImageinfo);

[png release];
[jpg release];

return ret;
}

but this function has never been invoked since cocos2d-x 1.0.1

I tried to do some profiling with instruments, but the weird thing happened:

  1. I can’t observe any spike
  2. After I load four 1024*2048 texture, I thought memory usage should increase 32M, but according to instruments, it only increase about 28M.

So I want to know:

  1. Will jpg cause higher momory usage spike
  2. How to track memory usage precisely?

Thanks.

Hi @cissyhope, have you found an answer to your questions?

sorry, no update yet

Did you find the answer ? :disappointed_relieved:

I’d suggest just using a profiler to decide this. You can see how your memory is before adding the jpg and then after you step over the code to add it…then you can see leaks as well.

I always use PNG’s. They are less file size, usually in my experience.

PNG usually bigger than JPEG because PNG is lossless format

1 Like

That is so interesting. I use an artist once in a while and they provide me app .jpgs and they are huge. I then save as PNG and they are much smaller. I need to look at why now.

It depend on image content also.
For photography JPEG is less in size and fine quality.
For game graphics PNG is better.