WhiteWolf424242 Posted April 4, 2021 Share Posted April 4, 2021 (edited) Hello, Is it necessary from the coder's end to free arrays allocated with "new" in papyrus? Or are they garbage collected?What I mean, is basically: is the following code leaking memory, or is this fine? Int[] myarray = new Int[10] myarray = new Int[20] myarray = new Int[20] myarray = new Int[20] ; Were the first 3 allocations freed automatically, or am I leaking memory? Thanks Edited April 4, 2021 by WhiteWolf424242 Link to comment Share on other sites More sharing options...
ReDragon2013 Posted April 5, 2021 Share Posted April 5, 2021 (edited) If you read the whole article here https://www.creationkit.com/index.php?title=Arrays_(Papyrus) you'll see this headline: "Assigning/Passing Arrays" int[] Array1 = new int[5] int[] Array2 = new int[10] Array2 = Array1 ; Array1 and Array2 now look at the same 5 element array, and Array2s original 10 element array is destroyed. The same applies to your sample which is using the same array variable. In case you want to destroy an array, which is a script variable or pre-filled as property look at these (it works for each array type like actor[], form[], string[], float[], ..): Int[] PROPERTY myArray auto ; pre-filled by CK Int[] a EVENT OnInit() a = new Int[128] ; script variable has been initialized Debug.Trace(" Array length is " + a.Length) ; 128 DestroyArray() Debug.Trace(" Array length is " + a.Length) ; Zero ENDEVENT FUNCTION DestroyArray() ;---------------------- int[] b ; set undefined array function variable of same type a = b ; destroy script variable myArray = b ; destroy property as well ENDFUNCTION Edited April 5, 2021 by ReDragon2013 Link to comment Share on other sites More sharing options...
WhiteWolf424242 Posted April 5, 2021 Author Share Posted April 5, 2021 Sooo... yes, they are.Thanks :) Link to comment Share on other sites More sharing options...
Recommended Posts