I noticed that loading a Texture consumes twice the memory it should but only while the texture is being loaded. I think i once read about it here but i'm not sure, which is why i'm posting this. It could also be a bug because i'm using 32-bit PNG in RGBA8888 format. I stepped through CCTexture2D and there is certainly no conversion being done.
When i load my texture atlases i ran into memory warnings. I have >20 MBs free in all cases, and am loading at most 14 MB of textures. Yet i got memory warnings. So i dove in to figure out what is going on.
I found out that each 1024x1024x32 PNG image takes twice the amount (8 MB) of memory but only while loading (in the same tick/step/frame), which is why i can't load my texture atlases all at once. After refactoring the texture loading into a scheduled method that runs at 0.1f interval i get the following output and no more memory warnings. Notice how each texture takes 8 MB during load, but when the next one is being loaded 4 MB have re-appeared.
Loading: Atlas_Tierteile1
start KB = 27516.000000 final KB = 18972.000000 diff = 8544.000000
Loading: Atlas_Tierteile2
start KB = 23144.000000 final KB = 15840.000000 diff = 7304.000000
Loading: Atlas_Tierteile3
start KB = 19960.000000 final KB = 12196.000000 diff = 7764.000000
Loading: Atlas_Tierteile4
start KB = 16632.000000 final KB = 15660.000000 diff = 972.000000
start KB = 16180.000000 final KB = 16180.000000 diff = 0.000000
`
I wonder, did anyone else run into this problem and how did you solve it? I'm currently thinking about writing a scheduled texture loader that loads them in sequence. But maybe it's also possible to force freeing the memory within the same step, possibly by draining the autorelease pool somehow?
I also came across "async" methods, can i use those or are they simply for thread-safe texture loading?