Clearing an array of types, how to?

BlitzMax Forums/BlitzMax Beginners Area/Clearing an array of types, how to?

Smurftra(Posted 2006) [#1]
I have an array

Array:MyType[]

I add some mytypes to it

Now i want to free the memory

If i do:

Array = Null

it is the same as looping through each element and setting them null:

Local i
For i = 0 to Array.length - 1
Array[i] = NULL
next

?


fredborg(Posted 2006) [#2]
Yes! Except Array = Null sets the array length to 0 as well. Both will remove all the types in the array.


Dreamora(Posted 2006) [#3]
To the elements within the array, the effect is the same.

But with Array = null the array can't be used afterwards anymore without reinitializing it once again through new MyType[XX]


Smurftra(Posted 2006) [#4]
super, thanks alot!


Grey Alien(Posted 2006) [#5]
So the GC will catch the fact that if the array is made null, all the pointers to types in the array should be made null also?


fredborg(Posted 2006) [#6]
Yes


Grey Alien(Posted 2006) [#7]
ok thanks. I'm so used to cleaning up myself I clean out the array pointers then set the array to null.