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.
  • Varine Varine:
    And since almost all of my programming experience is with defunct shit now, I figure my best place is helping preserve legacy stuff. Which I don't know how to do necessarily, but I need some kind of a hobby and figuring out how older things worked is the only shit that really interests me. Well soldering and restoration is fun too, but no one is bringing me new stuff to fix and restore, so it's mostly old shit, and I LOVE OG Xbox so much. I want to make sure it can function as long as possible, until someone can effectively emulate it at least. I have like 15 I was going to fix over the winter and didn't get to.
    +1
  • Varine Varine:
    I also have a couple OG gameboys, but idk if I can do that without like, manufacturing new parts that no one makes anymore and I can't do that right now
  • tom_mai78101 tom_mai78101:
    Currently in the middle of getting the probate process going. We're doing the informal probate process.
    +3
  • Varine Varine:
    A probate is usually done with a will, yes? If so I am sorry for your loss
    +1
  • The Helper The Helper:
    Yeah Tom, me too sorry for your loss buddy my mom told me she finds out her olds friend died from Google searching them. She had not talked to one of her old friends in a year and found out she died from Google. Also another one in the same session. RIP all of them my sincere condolences Tom
    +1
  • Varine Varine:
    We have some elderly guests that regularly come hang out at the bar at the end of the night, and every once in a while we don't see someone for a few weeks and then someone shows up with their obituary.
  • Varine Varine:
    We usually let them do their memorials there in the morning if they want to and I'll make them some snacks and drinks. There was one guy named Tom that came in like every night and would sit by himself and get a bunch of soup and a glass of wine. idk why but he LOVED our fucking soup, like he would order a fucking quart of it at a time and would always get so sad when we stop doing it for the summer.
    +1
  • Varine Varine:
    But he also loved our calamari, which is another thing I hate but it sells super well so I can't change it. There was one day he came in and was asking me how to make it, because he tried to at home once in the off season when we stop running it and he really wanted it lol
  • Varine Varine:
    I think he's one of the only people I've made recipes for for free because he really wanted a broccoli cheddar, and it was like dude I don't have a recipe, it's just whatever I have, but here, this is how you do it
  • Varine Varine:
    I don't think he ever figured out how to do the calamari in a pan though, like idk how to do that either. He was afraid of the at home deep fryers though and it's like yeah, that's fair, I am too
  • Varine Varine:
    He was just such a sweet old man, we had two servers pregnant and they held a baby shower together, he was soooooo fucking excited to get to see a baby. Unfortunately he died a month or so before they were born
  • The Helper The Helper:
    So I decided to Google some people that I had not seen or heard from in a while and sure enough one of my old best friends, we had a falling out years ago but whatever, find out he died of Pancreatic Cancer in January. I have also lost a few of my closer acquaintances from growing up the last year. Getting old - people die - I kinda thought it was going to be this way a few years ago....
    +2
  • The Helper The Helper:
    Forum running super slow again
  • Ghan Ghan:
    Not really clear from the stats as to what is causing the slowness.
  • Ghan Ghan:
    We get a lot of guest traffic so it may just be the load is getting too high and not from any particular source.
  • Ghan Ghan:
    Looks like the server is maxed out on CPU.
  • Ghan Ghan:
    Oh it looks like a lot of the traffic is Silkroad Forums. That domain isn't protected by Cloudflare.
  • Ghan Ghan:
    But the old Silkroad site is still on its own server. I just had a test site set up on this server for it.
  • Ghan Ghan:
    I just disabled that test site. Let's see if that helps the load.
  • Ghan Ghan:
    Looks much better already.
  • The Helper The Helper:
    I had actually forgot about the Silkroad site. I had asked
  • The Helper The Helper:
    SD Ryoko about it and he said the couple of people left on there really like it, that was a few years ago, maybe I should check back
  • jonas jonas:
    I guess when you're getting old, and the last day of soup season draws near, you start wondering
  • jonas jonas:
    will I make it to the start of the next season? or was this the last time I'll ever have my favorite dish?
  • The Helper The Helper:
    I am doing my first Vibe Coding project. In installed the environment and tools according to instructions but it is all chat doing this for me at my direction. It is fun really and holy shit I might finish in 2 hours what it would have taken a day to in my Access and this would be an electron app complete new

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials
      Top