- Home /
Loading external Image as Texture2D increases memory consumption dramatically on iOS
Hi folks,
i've a weird problem with loading external images as textures because the memory consumption increases unacceptable .
I'm currently loading about 100 images:
IEnumerator loadTexture(string url, GameObject cube) {
_textureURL = "file://" + Application.dataPath + "/../../Documents/webcontent/app/media/" + url;
_www = new WWW(_textureURL);
yield return _www;
_tempTexture = new Texture2D(256, 256);
_www.LoadImageIntoTexture(_tempTexture);
cube.renderer.material.mainTexture = _tempTexture;
}
The whole images are using approximately 2-3MB of disc space but if i run the profiler i can see that these images are using more than 200MB of memory! What's going on there?
I also tried to initialize the Texture2D with different texture formats but this is not working as well just as loading the assets via the "System.IO.File.ReadAllBytes"-method and then load it on the texture (_tempTexture.LoadImage(textureBytes).
Thanks in advance for your help!
No, but i've tried it with an image which is (loaded these image 100-times) - the result was the same but just in case i will give it one more try!
If they aren't power of two dimensions then it will get much bigger due to buffer allocations. Bear in $$anonymous$$d images in memory are always massively bigger than jpg or png files as those are compressed file formats.
Ok thanks! I've tried it but it turns out that a 512px x 512px .png image increases the memory much more than the other images. Here are the results from the profile:
Before loading the external images: http://www.equalion.de/help/before.jpg
After loading the external images: http://www.equalion.de/help/after.jpg
BTW: The .png image is using 101kb of disc space and i know that uncompressed images are getting bigger in memory than compressed ones but i can't believe that it increases from 10$$anonymous$$B disc space (100 * 101kb) to more than 400$$anonymous$$B in memory...
No the in memory size of your images is around 103$$anonymous$$B as a guess - one 512x512 image takes just over 1$$anonymous$$B of ram. The rest will be buffers etc used to import the image I imagine (it really is very costly). However, just because the OS profiler says you have that much memory does not mean that the application is using it - it can be allocated but not garbage collected yet.
Your answer
Follow this Question
Related Questions
Can I load textures at runtime with a smaller memory footprint? 1 Answer
Unloading asset bundles doesn't clear memory on iOS 1 Answer
Textures/Atlases and memory management 0 Answers
iPad real memory accumulation, how to prevent this? 1 Answer
Bug - Texture "corrupted" after sending on server with MultipartformDataSection, only on iOS 1 Answer