Notifications
Clear all

[Closed] Deallocating Variables

Is there a way to deallocate an array (or any other variable) in maxscript?

Something like: delete []array; in C++

gc() seems to slow the script I’m working on quite a bita when all I need is to deallocate the same array a through a few loops.

5 Replies
 rdg

just an idea:

theArray = #()

only guessing …

Georg

No, I think that just creates a new array, the old array will still be in memory waiting for garbage collection.

I’ve used this in the past:

theArray.count = 0

It clears the array… not sure about the memory though.

1 Reply
(@bobo)
Joined: 11 months ago

Posts: 0

Generally, the memory will be released at the next manual or automatic garbage collection, both light and full.

If you want to clean up manually, call

gc light:true

This will clean up memory that is NOT related to the scene objects, will preserve the undo stack and will be much faster than full gc().
Max 8 and 9 have much better automatic garbage collection which calls gc light:true internally whenever memory is needed and would release whatever is left of the old arrays, variable values etc. too.

Thanks Bobo, I was kinda afraid of that, even calling gc lite:true seems to slow my script down.

It’s not a huge script so maybe it would be best if I just rewrote it, I might be able to speed things up a bit that way.

Thanks for all the help guys