- Home /
Question by
dong.yu · Jan 21, 2016 at 01:18 PM ·
texture2dmemory-leak
How to release memory of Texture2D dynamic object, or is there a memory-leak?
I work on Unity5 & Win8, there's a simple test for the problem:
Memory looks well in Editor Profiler, but increases crazily in Windows Task Manager.
using UnityEngine;
public class TestMemoryLeak : MonoBehaviour {
float _nextCalcTime;
System.Random random = new System.Random();
void Update ()
{
if (Time.time >= _nextCalcTime) {
int size = 1024 + random.Next(-100, 100);
Texture2D tex = new Texture2D(size, size, TextureFormat.ARGB32, false);
DestroyImmediate(tex, true);
Resources.UnloadUnusedAssets();
System.GC.Collect();
_nextCalcTime = Time.time + 1f;
}
}
}
Comment