• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

When changing Variable Values: Will the old value leak?

Status
Not open for further replies.
Level 3
Joined
Mar 30, 2013
Messages
22
Hey guys,

i know what memory leaks are, but i came to this point, where i am not sure how they work:

If i create a Point via variable:
  • Set Nukepoint = (Center of (Playable map area))
And use the same variable later to store an other point:
  • Set Nukepoint = (Position of (Triggering Unit))
Will the first Point (Center of Playable map...) be removed/overwritten, or will it leak? So do i need to remove the variable, or is it just fine if i re-use my variables to avoid big leaks?
 
Level 9
Joined
Apr 23, 2011
Messages
460
If you overwrite in vJass does it leak?

I.E
JASS:
scope Hi initializer init
    private function UnitSpawn takes nothing returns nothing
        local unit u = CreateUnit(Player(0), 'hpal', 0, 0, 270.)
        call KillUnit(u)
        call RemoveUnit(u)
        set u = CreateUnit(Player(1), 'hpal', 0, 0, 270.)
    endfunction

    private function init takes nothing returns nothing
        call UnitSpawn()
    endfunction
endscope
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
But that makes no sense at all.
When we create variable we just seize some memory space.
If we change variable value we just change data in exact same memory space.

Dunno how this in wc3 works, but it's silly to think that:

set u = CreateUnit(...
...
set u = CreateUnit(...

can create memory leak...

So you expect the first unit to magically disappear?

@khamarr3524: Yes. Those are object variables. They do not make up the object but only point to it. Multiple variables can point to the same object. Resetting the variables does not destroy the object. Wc3 has no garbage collector that would free objects that are no longer accessible. Also types like units are interactive and fire events. Even without own variables they may have their function and show up at a later date.
 
Status
Not open for further replies.
Top