- Home /
Double memory for textures downloaded with www.....
So, here is my problem!
I have some png images in app directory on device
I use this code to load each texture
www = new WWW("file://" + Application.persistentDataPath + "/Folder/img.png");
yield return www;
Texture2D texture = www.texture;
int MemoryForTexture = texture.width * texture.height * 32; // for debug
www.Dispose ();
www = null;
When I check memory usage in profiler, It looks like total memory usage for texture is MemoryForTexture*2! Could you help me with this problem? Why my texture use double memory?
Answer by GameVortex · Mar 06, 2014 at 09:55 AM
The memory used for a texture is not width height 32. The memory used is depending on the format of the texture. JPG will be loaded as RGB24 which has a memory usage of approximately width height 3 (R, G and B). PNG will be loaded as ARGB32 which has a memory usage of approximate height width 4 (R, G, B and A). These are not absolute and memory usage may vary.
I am not sure how you check in the profiler how much memory the one texture you load uses, but the profiler is not accurate in this behaviour specifically when you profile the game in the editor. You get somewhat more accurate results when profiling a build.
Answer by DevMac1 · Mar 06, 2014 at 10:09 AM
I profiling my build in Xcode profiler on real device!
All my png are loaded as ARGB32!
int MemoryForTexture = texture.width texture.height 32; here I get memory in bits!
First, I load empty scene to check, how much memory it use! It is about 80 MB!
Then I launch script, which load textures! There is no other objects in scene! Only Camera! And script, which load textures in memory! So I can see the difference in memory usage! So, I have MemoryForTextures, which show me size of all downloaded textures in bits (or bytes)! And I have statistic of memory usage in Xcode profiler! For example, if all my textures are 40 Mb, in profiler I have 160Mb of memory usage! So 160 - 80 (in empry scene) = I get 80 Mb! But it should be 120 Mb!
You really like exclamation points don't you? =) You should by the way not post comments as answers.
I understand now, you are calculating memory in bits ins$$anonymous$$d of bytes. You are also on an IPhone or IPad and are using the XCode Profiler, which is information I would recommend you to include in the question itself.
I unfortunately do not know why the XCode profiler reports double memory usage. It may have to do with garbage collection or memory allocation. On a standalone pc build the Unity profiler shows the correct memory usage for my textures.
$$anonymous$$aybe you could try connecting the Unity Profiler to the build and see what it reports?
The Xcode memory profiler can be dodgy over actual memory usage. Some memory needs double counting on iOS due to the fact it exists in main memory and again for the video device. It depends which XCode tool you use as to what you actually see.