Array Destruction

Post » Tue Jun 19, 2012 10:48 pm

I'm a bit curious about what happens to an array once it's no longer referenced by any pointers. There's no "destroy" function to get rid of old arrays, so I'm assuming they get garbage collected?

Specifically, I'm going to have a case where I'm going to be shuffling arrays around like this:

int [] array00 = new int[10]int [] array01 = new int[10]int [] array02 = new int[10]int [] array03 = new int[10]; do stuff with arrays, and every once in a while:array03 = array02array02 = array01array01 = array00array00 = new int[10]

The array that array03 used to point to gets discarded, and array00 gets a new array initialized to zeros. But would it be better to do something like:

int [] tempArray = array03array03 = array02array02 = array01array01 = array00array00 = tempArrayZeroArray(array00)       ; iterates through the array setting each element to 0

That way the original arrays are reused, but you have to go through the iteration process to reset array00.
User avatar
ONLY ME!!!!
 
Posts: 3479
Joined: Tue Aug 28, 2007 12:16 pm

Post » Tue Jun 19, 2012 4:23 pm

My post was garbage too, sorry.
User avatar
Lindsay Dunn
 
Posts: 3247
Joined: Sun Sep 10, 2006 9:34 am

Post » Wed Jun 20, 2012 5:46 am

I would assume that a system similar to script-enforced http://www.creationkit.com/Persistence_(Papyrus) is used here, so that once an array becomes inaccessible it would be cleaned up.

I don't know of any reliable way in which this could be tested, though. I don't think this information is available anywhere on the wiki. Perhaps we could get a developer to weigh in here?

Cipscis
User avatar
Trey Johnson
 
Posts: 3295
Joined: Thu Oct 11, 2007 7:00 pm

Post » Tue Jun 19, 2012 10:16 pm

I would assume that a system similar to script-enforced http://www.creationkit.com/Persistence_(Papyrus) is used here, so that once an array becomes inaccessible it would be cleaned up.

I don't know of any reliable way in which this could be tested, though. I don't think this information is available anywhere on the wiki. Perhaps we could get a developer to weigh in here?

Cipscis

That’s correct, arrays are automatically cleaned up by the Papyrus garbage collector when no variable points at them anymore.
User avatar
Kelly Upshall
 
Posts: 3475
Joined: Sat Oct 28, 2006 6:26 pm

Post » Tue Jun 19, 2012 6:36 pm

That’s correct, arrays are automatically cleaned up by the Papyrus garbage collector when no variable points at them anymore.

Thanks. I added that info to the http://www.creationkit.com/Arrays_(Papyrus)#Assigning.2FPassing_Arrays article on the wiki under Assigning/Passing Arrays.

Turns out in my application I'll be processing each element in the last array right before I shuffle them around, so I can zero it while I'm at it and just recycle them, but this is still good to know.
User avatar
Anthony Santillan
 
Posts: 3461
Joined: Sun Jul 01, 2007 6:42 am


Return to V - Skyrim