DrHappy Posted January 11, 2016 Share Posted January 11, 2016 Simple question about garbage collection in Papyrus. Let's say I have a global variable in my mod which I allocate memory for like so: Int[] oldArray; event onConfigInit() oldArray = new Int[128] ; Do Stuff endEvent Later, I decide I don't like the name of the variable because it is inconsistent with my naming convention or something. I change all instances of the variable and then call the initial init routine using OnVersionUpdate Int[] newArray; event onConfigInit() newArray = new Int[128] ; Do Stuff endEvent event onVersionUpdate() onConfigInit() endEvent My question is, what happens to oldArray? This script is bound to a quest that is persistent (does not end), so the thread never ends. Does Skyrim know to delete it and unallocate the old 128 int array? Link to comment Share on other sites More sharing options...
sLoPpYdOtBiGhOlE Posted January 11, 2016 Share Posted January 11, 2016 (edited) The old array will still exist in the instance your explaining.In most cases your better off repuposing the old array in the instance your doing.Since your doing this in an MCM script and it requires SKSE, then maybe consider using a short call to SKSE.ResizeIntArray() or use CreateIntArray() functions to null the size of the array.eg:oldArray = Utlity.CreateIntArray(0)oroldArray = Utlity.ResizeIntArray(oldArray, 0) Best advice would be don't change global variable names (if it's in the instance your explaining about) if this is for a mod that will be updated mid way through a playthrough of a game without dropping the mod out of your load order.Think your script naming conventions out before hand and stick with it would be a better solution. Edited January 11, 2016 by sLoPpYdOtBiGhOlE Link to comment Share on other sites More sharing options...
Recommended Posts