- Home /
can someone help me with this error please?
I'm sorry i tried to find a solution elsewhere but i'm just a self student so can someone please tell me what is and how to fix this error?
OutOfMemoryException: Out of memory System.Array.Resize[Image] (UnityEngine.UI.Image[]& array, Int32 length, Int32 newSize) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System/Array.cs:1929) System.Array.Resize[Image] (UnityEngine.UI.Image[]& array, Int32 newSize) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System/Array.cs:1913) System.Collections.Generic.List`1[UnityEngine.UI.Image].set_Capacity (Int32 value) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/List.cs:622) System.Collections.Generic.List`1[UnityEngine.UI.Image].GrowIfNeeded (Int32 newCount) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/List.cs:100) System.Collections.Generic.List`1[UnityEngine.UI.Image].Add (UnityEngine.UI.Image item) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/List.cs:91) GameController.GetCodons () (at Assets/scripts/GameController.cs:44) GameController.Start () (at Assets/scripts/GameController.cs:34),I'm sorry I tried to find a Solution elsewhere but i'm just a self student. can someone please tell me what and how to fix this error? OutOfMemoryException: Out of memory System.Array.Resize[Image] (UnityEngine.UI.Image[]& array, Int32 length, Int32 newSize) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System/Array.cs:1929) System.Array.Resize[Image] (UnityEngine.UI.Image[]& array, Int32 newSize) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System/Array.cs:1913) System.Collections.Generic.List`1[UnityEngine.UI.Image].set_Capacity (Int32 value) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/List.cs:622) System.Collections.Generic.List`1[UnityEngine.UI.Image].GrowIfNeeded (Int32 newCount) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/List.cs:100) System.Collections.Generic.List`1[UnityEngine.UI.Image].Add (UnityEngine.UI.Image item) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/List.cs:91) GameController.GetCodons () (at Assets/scripts/GameController.cs:44) GameController.Start () (at Assets/scripts/GameController.cs:34)
Answer by andrew-lukasik · Oct 26, 2018 at 11:54 AM
You ran out of memory. That's it. Fix it by being more aware of how you allocate and release memory. This is an example of how you run out of memory:
void Update ()
{
// (CRUCIAL) Create texture object:
Texture2D memoryLeak = new Texture2D( 2^10 , 2^10 );
// Set it's pixels:
var pixels = memoryLeak.GetPixels();
for( int i=0 ; i<pixels.Length ; i++ ) { pixels[ i ] = Random.ColorHSV(); }
memoryLeak.SetPixels( pixels );
memoryLeak.Apply();
// Do something productive with that texture, like drawing it on screen:
Graphics.DrawTexture( new Rect(0,0,200,200) , memoryLeak );
/* NOTE: texture object is being created every frame but not reused or destroyed (deallocated) afterwards*/
}
It must happen eventually because every UnityEngine.Object is referenced by engine internally and wont be released by GC.Collect(). These objects must often be deallocated manually. Deallocations are performed by engine in some cases (scene change, for example) but not in every case.