- Home /
Question by
dong.yu · Jan 29, 2016 at 03:50 PM ·
bugmemory leak
Create Texture2D dynamic objects cause memory leak?
There's a simple test code for the problem, I tested on Unity5 & Win8:
Try to create some Texture2D dynamic objects and then release , 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