Hey, i have a variable that needs to store some rather big data, but after using it said data isn't needed anymore. Is there any way to delete it in code, without removing the entire node?

What kind of variable? If it's an Array or Dictionary, use its clear() method, or set it to an empty Array or Dictionary.

@DaveTheCoder said: What kind of variable? If it's an Array or Dictionary, use its clear() method, or set it to an empty Array or Dictionary.

Well i guess that would be an option, but it still doesn't fully delete it, does it? I was thinking of the equivalent of pythons del() function. Still, your method should release most of the memory, thanks.

The variable name is basically a pointer. It takes almost no memory, you could have a million variables, I think, without any problem. The issue would be the data that is stored in the variable, which you can delete using clear (on lists) or even just setting the variable to "null". Which will orphan the data and the garbage collector will reclaim the memory (after a short period of time).

I believe setting it to 'null' is enough to free it up for garbage collection (assuming there are no other references).

I've never had a problem by just setting the variable equal to null. I admit I always felt a bit dirty doing that tho instead of confining the variable in the scope of a function.

Yeah, if you are thinking you need to delete a variable, then maybe it should be of local scope.

Yep use as local scope as you can. Variables declared in function scope will be fully deleted upon function exit. Same goes for even smaller code blocks like loop bodies or if-blocks.

If you for some reason need to have global data that can be created/deleted on demand, put it into a class that inherits from Object. Calling free() on object of such a class will fully delete it.

Thanks to all of you, i think i've managed to do it now, i was able to make them local.

a year later