1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. We have recently started the 16th edition of the Mini Mapping Contest. The theme is mini RPG. Do check it out and have fun.
    Dismiss Notice
  4. Dismiss Notice
  5. The Highway to Hell has been laid open. Come along and participate in the 5th Special Effect Contest.
    Dismiss Notice
  6. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

Small Question Regarding Leaks

Discussion in 'Triggers & Scripts' started by Megafyr, Oct 5, 2009.

  1. Megafyr

    Megafyr

    Joined:
    Oct 29, 2007
    Messages:
    957
    Resources:
    1
    Tutorials:
    1
    Resources:
    1
    Code (vJASS):
    set l = Location(x, y)
    set l = Location(y, x)
    call RemoveLocation(l)


    Will l leak?

    I always do it like:

    Code (vJASS):
    set l = Location(x, y)
    call RemoveLocation(l)
    set l = Location(y, x)
    call RemoveLocation(l)


    But it seems like I am doing more than I have to. right? xD
     
  2. Reaper2008

    Reaper2008

    Joined:
    Jul 27, 2008
    Messages:
    1,117
    Resources:
    1
    Spells:
    1
    Resources:
    1
    Second one is right.
     
  3. Super-Sheep

    Super-Sheep

    Joined:
    Oct 21, 2006
    Messages:
    2,823
    Resources:
    1
    Maps:
    1
    Resources:
    1
    I have asked this same question and I was told that first one was right. -.-

    not sure thought that did I understand what you mean, cause of y,x stuff.
     
  4. Diablo-dk

    Diablo-dk

    Joined:
    Nov 10, 2004
    Messages:
    369
    Resources:
    3
    Maps:
    1
    Spells:
    1
    Tutorials:
    1
    Resources:
    3
    The second example is the right way to do it.

    An easy way to understand why, is to think of locations as objects. Each time you do a Location(x, y) call, you create a new object that has to be removed later, and since you are creating 2 locations but only removing one of them in your first example, it will leak.

    By the way, it is more efficient to use a single global location instead of local locations, since you always have to create and destroy them, whereas you can just do a MoveLocation() call with a global location.
     
  5. Reaper2008

    Reaper2008

    Joined:
    Jul 27, 2008
    Messages:
    1,117
    Resources:
    1
    Spells:
    1
    Resources:
    1
    Best explanation possible is a small explanation of pointers.

    If you have:
    Code (vJASS):
    local location loc
    set loc = Location (0, 0)
    set loc = Location (1, 1)
    call Remove Location(loc)


    The variable points to the location, it isn't the location. And if you change it the location it pointed to before remains, but it is unreachable, and eats up memory (= leak).
     
  6. Megafyr

    Megafyr

    Joined:
    Oct 29, 2007
    Messages:
    957
    Resources:
    1
    Tutorials:
    1
    Resources:
    1
    Thank you for your answers! I understand it now.
     
  7. Saia_Djinn

    Saia_Djinn

    Joined:
    Feb 15, 2009
    Messages:
    458
    Resources:
    0
    Resources:
    0
    but you should also
    Code (vJASS):
    null
    the variable or it will still leak a lil bit after removing
     
  8. The Reborn Devil

    The Reborn Devil

    Joined:
    Dec 31, 2006
    Messages:
    1,325
    Resources:
    0
    Resources:
    0
    When you have local variables you must null them if they are handles with the exception of players. And the second one is right.
    Code (vJASS):

    local location l
    set l = Location(0., 0.)
    call RemoveLocation(l)
    set l = Location(0., 0.)
    call RemoveLocation(l)
    set l = null
     
     
  9. Megafyr

    Megafyr

    Joined:
    Oct 29, 2007
    Messages:
    957
    Resources:
    1
    Tutorials:
    1
    Resources:
    1
    I always do that.