testiger2 Posted April 10, 2019 Share Posted April 10, 2019 Hi everyone, I have a question about the "new" keyword in papyrusDoes it behave like "new" in c++ where you always have to delete manually to prevent memory leaks? so if i do something like this int[] myArr ;owner is playerAlias aka persisent ref Event xxEvent myArr = new int[10] ;do something Endevent Event yyEvent ;myArr no longer needed myArr = none Endevent will the pre-reserved memory also be freed or is there a special delete/clear function for arrays?or will it be garbagecollected like normal variables when leaving scope? Link to comment Share on other sites More sharing options...
Evangela Posted April 10, 2019 Share Posted April 10, 2019 Arrays are automatically garbage collected, when the array is no longer reference. Usually after the loop has finished for example. Link to comment Share on other sites More sharing options...
testiger2 Posted April 10, 2019 Author Share Posted April 10, 2019 sure but the point is that the array(s) are declared in script-global scopethe question is if the event runs a second time willmyArr = new int[10]start the garbage collector or will it simply point to a new memory seg and leave the old data in heap like in c++?same question for myArr = none Link to comment Share on other sites More sharing options...
foamyesque Posted April 11, 2019 Share Posted April 11, 2019 Papyrus garbage collection's entirely automatic; as long as you stop references to it, the memory will be deallocated, and if anything goes wrong after you dereference stuff, you can't fix it anyway because there is no way to manually deallocate memory in Papyrus :p Link to comment Share on other sites More sharing options...
testiger2 Posted April 11, 2019 Author Share Posted April 11, 2019 haha gotcha, thanks guys Link to comment Share on other sites More sharing options...
Recommended Posts