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
// convert jpg to png before loading the texture
NSString *fullPath = ;
jpg = initWithContentsOfFile: fullPath];
png = initWithData:UIImagePNGRepresentation];
CGImage = png.CGImage;
ret =*initWithImage(CGImage, pImageinfo);
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:
- I can’t observe any spike
- 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:
- Will jpg cause higher momory usage spike
- How to track memory usage precisely?