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

Way to check for leaks manually?

Status
Not open for further replies.
Level 4
Joined
Sep 25, 2005
Messages
71
Is there some manner of fashion I can check if I'm inadvertently leaking? I mean, I can't tell if this is bad:

JASS:
    private static method Check takes nothing returns boolean
        return not IsUnitAlly(GetAttacker(), GetOwningPlayer(GetTriggerUnit()))/*
        */and GetUnitAbilityLevel(GetTriggerUnit(), ABIL_ID) >= 1 /*
        */and ValidGroundTarget(GetAttacker(), GetTriggerUnit())
    endmethod

compared to this:

JASS:
    private static method Check takes nothing returns boolean
        local unit attacker = GetAttacker()
        local unit attacked = GetTriggerUnit()
        if not IsUnitAlly(attacker, GetOwningPlayer(attacked))/*
        */and GetUnitAbilityLevel(attacked, ABIL_ID) >= 1 /*
        */and GetUnitAbilityLevel(attacked, REAL_ID) >= 1/*
        */and ValidGroundTarget(attacker, attacked) /*
        */and IsUnitInRange(attacker, attacked, RANGE) then
            call CounternovaData.create()
        endif
        set attacker = null
        set attacked = null
        return false
    endmethod

Basically, I know you need to remove/destroy/then null anything not integer, real, boolean or string, right? Does .destroy() a struct work correctly for ALL the variables or do say, units need removed from inside an .onDestroy() method? That's what I've been doing just for safe sake.

I'd just like to know if the wc3 memory usage will change or anything that can alert me to whether I did something wrong or right exists. I remove and null all my handles that I'm aware of, but I'm not sure whether I missed something...
 
Level 22
Joined
Sep 24, 2005
Messages
4,821
Leaks are associated with local variables pointing to handle type objects, that after being used, is not set to point to null. Global variables can also cause leaks but the global variable is not lost unlike the local one.

The game engine's garbage collector only releases memory occupied by an object when the said memory has no existing reference (a variable, can be global or local) to it.

A variable (in jass), specifically handle types, are pointers to objects in memory (units, timers, groups, triggers, etc.). Local variables, if behaving properly, should have been removed from memory once the function returns, but this does not happen in jass, that's why the local variables persist after the function where it was created has already ended. It exists still, but it is unreachable, and because it points to an object, the garbage collector will not return the memory used by the said object.

I hope I remember it correctly though.
 
Status
Not open for further replies.
Top