New Leak Found: Keeping references to destroyed objects.

Jesus4Lyf

Good Idea™
Reaction score
397
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.
 
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
 
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?
 
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
 
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?
 
Tested. Setting a variable(contains destroyed value) to a new value will cause leaking.
 
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.
 
Then why did they fix local masking? I can't see how that would affect their income.
 
Actually, according to Vexorian, local masking works perfectly now. ( link )

Noone really knows what Blizzard is doing and why...
 
>Then why did they fix local masking?

Because apparently typecasting could be done via shadowing. So Blizzard decided to fixit. Or something.
 
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.
 
Oh hey look, a new leak...
Just another thing I need to learn how to fix. OH WELL.
 
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.
 
Yeah, well... It's still another thing to remember. And I'm really bad at remembering...
 
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:
    How often does the Trending Content box refresh?
  • The Helper The Helper:
    Also, in the last template there was a seperation between sticky threads and regular threads in the forum
  • Ghan Ghan:
    Not sure. It's probably part of a cron job.
  • The Helper The Helper:
    Hey Ghan, whatever cron job its part of its not running its been the same for days. If it does not work can we remove it?
  • The Helper The Helper:
    LOL! A tweak job!
  • The Helper The Helper:
    this is the fix I get from that yeah this is hard to control. disabling bots is pretty much necessary as ai and other bots would push really old threads to the top. reduce weight of view count. disable guest view tracking if you really want to push active threads to the top. a bit of tinkering for a few days with the weights and other settings should get you a decent trending widget box.
  • Ghan Ghan:
    I changed the settings a bit.
  • Ghan Ghan:
    Narrowed it to 7 days for the half-life and set views to 0 weight.
  • The Helper The Helper:
    I dont think Trending would work for this forum it would be better to just have the last 5 posts from anywhere
  • Ghan Ghan:
    Probably will have to give it some time to update.
  • Ghan Ghan:
    I'm guessing it is not retroactive.
  • Ghan Ghan:
    Next on the punch list: Update the server to Ubuntu 24.04.
  • The Helper The Helper:
    Mad Lads is new I see it displays original post date
  • The Helper The Helper:
    as long as it changes it is good - it is good now it updated and its new stuff
  • The Helper The Helper:
    One thing I have noticed and I dont know if it is by design but like 1 out of 3 times I come to the site the Anubis screen just hangs open, if I refresh it will go away but sometimes it hangs
  • Ghan Ghan:
    I've seen that as well.
  • The Helper The Helper:
    Wow - the change in the stats are major. I kind of knew it was all bots but wow, to see the effect. Why the social media sites cant do something like this I have no idea.
  • Ghan Ghan:
    Probably inflates their numbers so they look better to advertisers.
  • The Helper The Helper:
    Yeah google does not filter those bots. I remember when Apex was doing Google ads I saw the same IPs in there as I was seeing here - google is totally tracking all those bots as traffic and most google traffic, at least ours, was all bots
  • The Helper The Helper:
    oh wow, i bet i can post x links now and do the webp pics now giggity
  • The Helper The Helper:
    ahh anubis blocks anyone that has javascript turned off
  • The Helper The Helper:
    Robot: HTTP client library - i love the new robot :)
  • The Helper The Helper:
    New Science News Forum and it starts out with 420 threads :)
  • The Helper The Helper:
    Technical Support forum name changed To Technology News, there is now a Tech, sci/tech and science forums now :)

The Helper Discord

Members online

No members online now.

Affiliates

Hive Workshop NUON Dome World Editor Tutorials
Back
Top