• 🏆 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!

(general question) What exactly is a leak?

Status
Not open for further replies.
Level 3
Joined
Feb 18, 2005
Messages
50
I have my assumptions, but I never found one way or another what they are or what problems they cause. I'm pretty sure I've seen them in action (I.E. Unit going to a random location instead of the location I wanted because the trigger was too basic and didn't watch for any leaks) but I wanted to know exactly what they are and couldn't find any FAQ to answer my question :(

Regards,
Michael
 
Level 11
Joined
Feb 22, 2006
Messages
752
There's two types of leaks. Handle object leaks and reference leaks.

You get handle object leaks when you don't destroy/remove handles when you're done with them. Handles are all data types except for integer, real, string, boolean, and code. This type of leak is the far more important one to control, because leaking handle objects can easily lag your map.

The second type of leaking is reference leaks. This is just not nulling handle references (variables) that reference handles that are either destroyed or will be destroyed in the future. The reason why you have to do this is complicated but suffice it to say blizz's garbage collection system in wc3 is bugged and forces us to do this. It takes a LOT of leaks of this type to even get any noticeable effects but they should still be cleaned up.
 
Level 3
Joined
Feb 18, 2005
Messages
50
okay, sounds simple enough. Lemme see if I got this straight:

Handle leaks happen when I forget to make variables and then delete said variables, stuff like that. (Probably the more common one in my maps xD)

Reference leaks won't happen in triggers that are set up to have a location, use the location, and then delete the location's variable, but WOULD occur if that same location that was deleted was used by another trigger right afterwards. Right?
 
Level 11
Joined
Feb 22, 2006
Messages
752
You can't delete variables. Handle variables in JASS are just references to the actual handle objects. You can destroy handle objects by calling the appropriate Remove/Destroy function on an object, which prevents handle object leaks.

You can null handle references, which doesn't destroy the object it was referencing (if there was one), but this DOES prevent reference leaks IF the object it was referencing was/will be destroyed.

For example:

JASS:
function foo takes nothing returns nothing
    local location loc = Location(0, 0) // created location object
    local group g = CreateGroup() // created group object
endfunction

Those two handles (location and group) created will leak if not destroyed. So we destroy them:

JASS:
function foo takes nothing returns nothing
    local location loc = Location(0, 0)
    local group g = CreateGroup()
    call RemoveLocation(loc) // removed location object
    call DestroyGroup(g) // removed group object
endfunction

However, this creates reference leaks since the objects local variables loc and g were referencing are now destroyed.

We can fix those leaks by nulling the variables:

JASS:
function foo takes nothing returns nothing
    local location loc = Location(0, 0)
    local group g = CreateGroup()
    call RemoveLocation(loc)
    call DestroyGroup(g)
    set loc = null // nulled location reference
    set g = null // nulled group reference
endfunction

Because reference leaks won't happen if the object being referenced is never destroyed, you don't need to null variables that reference objects that will never be destroyed.
 
Level 3
Joined
Feb 18, 2005
Messages
50
Ahhh!!! I get it now!

Thanks for breaking it down into simple examples :D

and thanks ferocity for explaining how the two errors he explained cause a problem :D
 
Status
Not open for further replies.
Top