I've been away from DBC and DBPro for the last few years, but I was recently asked to make a Mac version of an old scoreboard program I'd done in DBC and so I thought I'd give AppGameKit a try. One thing that confuses me (coming after 4+ years of working with C++) is that variables have a much longer lifetime than I expected. For example in this code:
ArrayLength = 0
for n=1 to 5
IntArray as integer[]
IntArray.insert(n)
ArrayLength = IntArray.Length
next n
do
Print(ArrayLength)
Sync()
loop
I thought IntArray would be recreated as an empty array at the start of each loop, leaving the final array length as 0, but instead there is only one IntArray and it just gets longer and longer. It's as though I had written this instead:
ArrayLength = 0
IntArray as integer[]
for n=1 to 5
IntArray.insert(n)
ArrayLength = IntArray.Length
next n
The same issue is also true of variables, I noticed that "ArrayLength" can be declared inside the for-loop and still accessed after the for-loop has finished.
Can anyone tell me what's the actual lifetime of variables and arrays, and at what point do they get cleaned up (if at all)?
If an array is created inside a function, should UnDim be called before the function exits/ends?
Finally, if you create a variable of a user type and that user type contains an array, how do you handle it's cleanup?
We spend our lives chasing dreams. Dark Basic lets us catch some of them.