Hello,
I'm using WWW for creating textures. Here is the script.
using UnityEngine; using System.Collections; using System;
public class NewBehaviourScript : MonoBehaviour { WWW _www = null; Texture2D _texture = null;
IEnumerator Loading()
{
Debug.Log("Loading..." + GC.GetTotalMemory(true).ToString());
_www = new WWW("http://saveimg.ru/pictures/23-06-10/bd328a508c9105f873ef4a2a0994f7ed.png");
yield return _www;
Debug.Log("Loaded..." + GC.GetTotalMemory(true).ToString());
_texture = _www.texture;
//_texture.Compress(false);
_www.Dispose();
_www = null;
Debug.Log("WWW released..." + GC.GetTotalMemory(true).ToString());
}
void Update()
{
if (Input.GetKeyDown("a") && _www == null && _texture == null)
{
Debug.Log("Update StartCoroutine" + GC.GetTotalMemory(true).ToString());
StartCoroutine(Loading());
}
if (Input.GetKeyDown("s") && _www == null && _texture != null)
{
Debug.Log("Update Destroy" + GC.GetTotalMemory(true).ToString());
Destroy(_texture);
_texture = null;
}
}
}
Then I'm trying to get texture from WWW, Unity allocates about 20 Mb of memory (according to internal profiler)
But actually I'm expecting it to allocate 4 Mb. (1000*1000 pixels) * 4 rgba size = 4 000 000 bytes
Is there any way to load texture with out any unexpected memory allocations?