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

Handle Counter?

Status
Not open for further replies.
Level 14
Joined
Dec 12, 2012
Messages
1,007
Hello,

I am looking for a system that gives me the number of handles in my map. I need this to detect very small memory leaks that occure in rare situations.

I already searched a bit and found this one, but there it is said that this will only work if you have massive leaks in your map.

I also found this very simple solution:

JASS:
function HandleCount takes nothing returns nothing
    local location L = Location(0,0)
    call BJDebugMsg(I2S(GetHandleId(L)-0x100000))
    call RemoveLocation(L)
    set L = null
endfunction

//===========================================================================
function InitTrig_HandleCounter takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterTimerEvent(t,0.09,true)
    call TriggerAddAction(t,function HandleCount)
endfunction

But somehow the handle counter keeps increasing although my map doesn't contain any leaks (testmap with no leaks).

So... Is there a system that can give me the exact handle count?

Any help is appreciated.

lfh
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
maker is right, handle id is not recycled instantly but it takes them in batches(I have experienced this when I was trying to make some timer utils by myself(never made any :D) but the handles were increasing and then decresed drastically like 3k values)

You just have to wait long enough for them to recycle
 
Level 14
Joined
Dec 12, 2012
Messages
1,007
I believe handles aren't instantly recycled, that could cause the id increase.

You just have to wait long enough for them to recycle

Hm, it seems that you are right, when I wait long enough the handle IDs drop down again. Its just a little bit strange that the numbers seem to alter between two different values.

So, I can use both of the posted systems? Or is one of them better? And why in the linked thread those guys said that this would only work for heavy leaks?

lfh
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
I would use something like this:

JASS:
library HandleCounter
    function GetHandleCounterOnMap takes nothing returns integer
        local trigger t = CreateTrigger()
        local integer i = GetHandleId(t)
        call DestroyTrigger(t)
        set t = null
        return i - 0x100000
    endfunction
endlibrary

it may be off by 0x000059 according to TrollBrain, I dont know how he came to that conclusion tho

I would not recommend using their script because of this:
JASS:
private function L2I takes location loc returns integer
    return loc
    return 0
endfunction

if you try to compile it, it will compile fine but it will not start the map

if you want the leaderboard, I could make something

and the time is very simple to do also
 
Level 14
Joined
Dec 12, 2012
Messages
1,007
I would use something like this:

JASS:
library HandleCounter
    function GetHandleCounterOnMap takes nothing returns integer
        local trigger t = CreateTrigger()
        local integer i = GetHandleId(t)
        call DestroyTrigger(t)
        set t = null
        return i - 0x100000
    endfunction
endlibrary

it may be off by 0x000059 according to TrollBrain, I dont know how he came to that conclusion tho

Ok, then I will use this.

I would not recommend using their script because of this:
JASS:
private function L2I takes location loc returns integer
    return loc
    return 0
endfunction

if you try to compile it, it will compile fine but it will not start the map

Well, they have actually two versions. One for pre-1.24 which abuses the return bug and one without, which I was using.

if you want the leaderboard, I could make something

Thanks, but I don't need the leaderboard, just the information.

So thank you both for your help.

lfh
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
well, if the second one isnt using return bug and does pretty much same calculation as mine, you can use theirs, its just fine
it will let you know about any handle leaks whatsoever, the only problem is the fact that they reset over time not instantly
 
Status
Not open for further replies.
Top