New Leak Found: Keeping references to destroyed objects.

Jesus4Lyf

Good Idea™
Reaction score
395
These are memory leaks (but not handle id leaks). You must check the process list to see it leak.
Credits to Troll-Brain for finding the original leak.

This leaks:
JASS:
library Test initializer init

globals
    private group G1
    private group G2
    private group GROUP=CreateGroup()
    private trigger Trig
endglobals

private function Actions takes nothing returns nothing
    call BJDebugMsg("Start")
    call EnableTrigger(Trig)
    call TriggerSleepAction(10.)
    call DisableTrigger(Trig)
    call BJDebugMsg("End")
endfunction

private function DoTheTest takes nothing returns nothing
    //call BJDebugMsg("run")
    set G1=null // With or without this line.
    set G1=CreateGroup()
    call DestroyGroup(G1)
endfunction

private function init takes nothing returns nothing
    local trigger trig = CreateTrigger()
    set Trig = CreateTrigger()
    
    call TriggerRegisterTimerEvent(Trig,0.0,true)
    call TriggerAddAction(Trig,function DoTheTest)
    call DisableTrigger(Trig)
    
    call TriggerRegisterPlayerEventEndCinematic(trig,Player(0))
    call TriggerAddAction(trig, function Actions)
endfunction

endlibrary
In fact, even this leaks:
JASS:
library Test initializer init

globals
    private group G1
    private group G2
    private group GROUP=CreateGroup()
    private trigger Trig
endglobals

private function Actions takes nothing returns nothing
    call BJDebugMsg("Start")
    call EnableTrigger(Trig)
    call TriggerSleepAction(10.)
    call DisableTrigger(Trig)
    call BJDebugMsg("End")
endfunction

globals
    boolean k=false
endglobals

private function DoTheTest takes nothing returns nothing
    //call BJDebugMsg("run")
    if k then
        set G1=null
    else
        set G1=CreateGroup()
        call DestroyGroup(G1)
    endif
    set k = not k
endfunction

private function init takes nothing returns nothing
    local trigger trig = CreateTrigger()
    set Trig = CreateTrigger()
    
    call TriggerRegisterTimerEvent(Trig,0.01,true)
    call TriggerAddAction(Trig,function DoTheTest)
    call DisableTrigger(Trig)
    
    call TriggerRegisterPlayerEventEndCinematic(trig,Player(0))
    call TriggerAddAction(trig, function Actions)
endfunction

endlibrary
This does not leak:
JASS:
library Test initializer init

globals
    private group G1
    private group G2
    private group GROUP=CreateGroup()
    private trigger Trig
endglobals

private function Actions takes nothing returns nothing
    call BJDebugMsg("Start")
    call EnableTrigger(Trig)
    call TriggerSleepAction(10.)
    call DisableTrigger(Trig)
    call BJDebugMsg("End")
endfunction

private function DoTheTest takes nothing returns nothing
    //call BJDebugMsg("run")
    set G1=CreateGroup()
    call DestroyGroup(G1)
    set G1=null
endfunction

private function init takes nothing returns nothing
    local trigger trig = CreateTrigger()
    set Trig = CreateTrigger()
    
    call TriggerRegisterTimerEvent(Trig,0.0,true)
    call TriggerAddAction(Trig,function DoTheTest)
    call DisableTrigger(Trig)
    
    call TriggerRegisterPlayerEventEndCinematic(trig,Player(0))
    call TriggerAddAction(trig, function Actions)
endfunction

endlibrary
What's the exact cause? Discuss. I will update this post as conclusions are reached and verified.

This is a minor leak.

Conclusion:
Not allowing a handle id to be recycled immediately after destruction causes a memory leak.
 

Jesus4Lyf

Good Idea™
Reaction score
395
I have a new conclusion. We know that the handle id recycler will pick up a handle at any point after it has been destroyed, when its reference count hits 0.

Well, it seems if that is not immediately after it is destroyed, then it causes a leak.

I conclude this because setting the variable to "GROUP" (a constant group) also stops the leak.

Edit: Yep.
Does not leak:
JASS:
library Test initializer init

globals
    private group G1
    private group G2
    private group GROUP=CreateGroup()
    private trigger Trig
endglobals

private function Actions takes nothing returns nothing
    call BJDebugMsg("Start")
    call EnableTrigger(Trig)
    call TriggerSleepAction(10.)
    call DisableTrigger(Trig)
    call BJDebugMsg("End")
endfunction

private function OtherTest takes nothing returns nothing
    local group g=CreateGroup()
    call DestroyGroup(g)
    set g=null
    call TriggerSleepAction(0)
endfunction

private function DoTheTest takes nothing returns nothing
    //call BJDebugMsg("run")
    call OtherTest.execute()
endfunction

private function init takes nothing returns nothing
    local trigger trig = CreateTrigger()
    set Trig = CreateTrigger()
    
    call TriggerRegisterTimerEvent(Trig,0.0,true)
    call TriggerAddAction(Trig,function DoTheTest)
    call DisableTrigger(Trig)
    
    call TriggerRegisterPlayerEventEndCinematic(trig,Player(0))
    call TriggerAddAction(trig, function Actions)
endfunction

endlibrary
Does leak:
JASS:
library Test initializer init

globals
    private group G1
    private group G2
    private group GROUP=CreateGroup()
    private trigger Trig
endglobals

private function Actions takes nothing returns nothing
    call BJDebugMsg("Start")
    call EnableTrigger(Trig)
    call TriggerSleepAction(10.)
    call DisableTrigger(Trig)
    call BJDebugMsg("End")
endfunction

private function OtherTest takes nothing returns nothing
    local group g=CreateGroup()
    call DestroyGroup(g)
    call TriggerSleepAction(0)
    set g=null
endfunction

private function DoTheTest takes nothing returns nothing
    //call BJDebugMsg("run")
    call OtherTest.execute()
endfunction

private function init takes nothing returns nothing
    local trigger trig = CreateTrigger()
    set Trig = CreateTrigger()
    
    call TriggerRegisterTimerEvent(Trig,0.0,true)
    call TriggerAddAction(Trig,function DoTheTest)
    call DisableTrigger(Trig)
    
    call TriggerRegisterPlayerEventEndCinematic(trig,Player(0))
    call TriggerAddAction(trig, function Actions)
endfunction

endlibrary
 

T.s.e

Wish I was old and a little sentimental
Reaction score
133
I still don't see why you would want to destroy a global group, but it is probably an example that applies to handles in general?
 

Zwiebelchen

You can change this now in User CP.
Reaction score
60
So the conclusion is: Even globals have to be nulled after destruction.

One question: Does this leak? If yes, then globals have to be nulled immediately and not only inside the same instance.

JASS:

set G1 = CreateGroup()
call DestroyGroup(G1)
call DoNothing()
set G1 = null
 

Jesus4Lyf

Good Idea™
Reaction score
395
This also leaks (demo using hashtables):
JASS:
library Test initializer init

globals
    private group G1
    private group G2
    private group GROUP=CreateGroup()
    private trigger Trig
    private hashtable H=InitHashtable()
endglobals

private function Actions takes nothing returns nothing
    call BJDebugMsg("Start")
    call EnableTrigger(Trig)
    call TriggerSleepAction(10.)
    call DisableTrigger(Trig)
    call BJDebugMsg("End")
endfunction

private function DoTheTest takes nothing returns nothing
    call SaveGroupHandle(H,0,0,CreateGroup())
    call DestroyGroup(LoadGroupHandle(H,0,0))
endfunction

private function init takes nothing returns nothing
    local trigger trig = CreateTrigger()
    set Trig = CreateTrigger()
    
    call TriggerRegisterTimerEvent(Trig,0.0,true)
    call TriggerAddAction(Trig,function DoTheTest)
    call DisableTrigger(Trig)
    
    call TriggerRegisterPlayerEventEndCinematic(trig,Player(0))
    call TriggerAddAction(trig, function Actions)
endfunction

endlibrary
This does not leak (hashtables):
JASS:
private function DoTheTest takes nothing returns nothing
    call SaveGroupHandle(H,0,0,CreateGroup())
    call DestroyGroup(LoadGroupHandle(H,0,0))
    call SaveGroupHandle(H,0,0,GROUP)
endfunction

Neither does this:
JASS:
private function DoTheTest takes nothing returns nothing
    call SaveGroupHandle(H,0,0,CreateGroup())
    call DestroyGroup(LoadGroupHandle(H,0,0))
    call RemoveSavedHandle(H,0,0)
endfunction

>One question: Does this leak? If yes, then globals have to be nulled immediately
No, it does not (tested). But remember, nulling after a wait does (if the handle is removed during the wait).

So the conclusion is solid?
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
Tested. Setting a variable(contains destroyed value) to a new value will cause leaking.
 

Azlier

Old World Ghost
Reaction score
461
Nay, Blizzard only fixes things that affect their income. Virus maps, yeah, suing could happen there. But a minor memory leak that people found out about eight years later? I don't think so.
 

T.s.e

Wish I was old and a little sentimental
Reaction score
133
Then why did they fix local masking? I can't see how that would affect their income.
 

Viikuna

No Marlo no game.
Reaction score
265
Actually, according to Vexorian, local masking works perfectly now. ( link )

Noone really knows what Blizzard is doing and why...
 

Azlier

Old World Ghost
Reaction score
461
>Then why did they fix local masking?

Because apparently typecasting could be done via shadowing. So Blizzard decided to fixit. Or something.
 

uberfoop

~=Admiral Stukov=~
Reaction score
176
I guess that at least (partially) explains the slow memory increases of supposedly leak free maps that aren't increasing in active object count.

On the plus side, these leaks are tiny and generally preventable.
 

Lyerae

I keep popping up on this site from time to time.
Reaction score
105
Oh hey look, a new leak...
Just another thing I need to learn how to fix. OH WELL.
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
Oh hey look, a new leak...
Just another thing I need to learn how to fix. OH WELL.
It's not that hard, just set to null the handle variable just after you have destroyed the handle, or flush gamecache/hashtable if you used it instead of a variable.

According to Jesus4Lyf you might can do it after few lines of code without waits, but i recommend to set to null in the line just below the handle destruction, just to be sure, at least it's more likely you won't forget it.
 

Lyerae

I keep popping up on this site from time to time.
Reaction score
105
Yeah, well... It's still another thing to remember. And I'm really bad at remembering...
 

uberfoop

~=Admiral Stukov=~
Reaction score
176
If you just recycle what can be recycled in a practical manner you should be fine. That's more efficient anyway than create and destroy, and results in cleaner end code (ie no need to null anything). Global group + GroupClear for instant-use groups, GroupUtils or some other recycler for other groups, TU and maybe T32 for timers depending on what you are doing/need, etc.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • The Helper The Helper:
    Happy Monday!
  • Ghan Ghan:
    Monday? Speak for yourself. :p
    +2
  • The Helper The Helper:
    Happy Taco Tuesday!
    +1
  • The Helper The Helper:
    Tacos! :)
  • The Helper The Helper:
    Check out the discord for taco pictures :) You cannot put pictures in this chat
    +1
  • The Helper The Helper:
    Damn here come the bots again - 193 online but they are totally invisible to any stats - bunch of bots!'
  • C cubanismo:
    Re: Taco Tuesday, if there were some way to share edible tacos over the internet, technology would be complete.
    +2
  • The Helper The Helper:
    One can only wish!
  • tom_mai78101 tom_mai78101:
    I'm back from Taiwan
    +1
  • The Helper The Helper:
    I am reorganizing the site I know nobody will notice but I am not done quite yet but the main forums order has been changed and there is a new news category in Other News which is all the remaining headline news stuff not categorized - Headline News is just the stuff that shows on the main page now and the news archive is off the main forums page
  • The Helper The Helper:
    and the real archive lives off of headline news
  • The Helper The Helper:
    Happy Monday!
  • V-SNES V-SNES:
    Happy Saturday!
  • The Helper The Helper:
    Happy Saturday Night!
    +1

    The Helper Discord

    Staff online

    Members online

    Affiliates

    Hive Workshop NUON Dome World Editor Tutorials

    Network Sponsors

    Apex Steel Pipe - Buys and sells Steel Pipe.
    Top