Stack.Pop() doesn't actually free?
Monkey Forums/Monkey Bug Reports/Stack.Pop() doesn't actually free?
| ||
I was just examining the source of monkey's Stack and i noticed the Pop() method.Method Pop:T() length-=1 Return data[length] End It seems it doesn't actually remove the instance stored from the stack! Shouldn't the code be: Method Pop:T() length -= 1 Local value:= data[length] data[length] = Null Return value End ??? otherwise how is the stack letting the garbage collect the popped value? |
| ||
Same goes for Remove() it is shifting all values 1 but the last value still holds a pointer to whatever it was as it is not being nulled. And also Clear()... Crikey, am I being thick here and missing something or is stack currently a memory-leak/reference-hog? What if I dumped say 100 objects on the stack and each object stored an image, some strings and general game data. Then I clear the stack a few frames later. Unless I repopulated the stack those 100 objects, images and vars would all stay in memory? |
| ||
Yes...in general, I don't like to add '=Null' code everywhere to try and second guess GC, but in this case it's definitely a good idea! |
| ||
Phew I'm not going Insane then haha! |
| ||
This is one of the reasons I've been using Diddy's ArrayList instead. |