What are handles?

Legacyspy

New Member
Reaction score
19
I've seen this referenced a lot and I don't understand what they are other than some sort of stored info.
Also I recall hearing about a handle counter that would display it in game, could anyone link to one?
 

Romek

Super Moderator
Reaction score
963
A handle is everything that isn't an integer, real, string, boolean or code.
Basically objects in the game, such as units, triggers, timers, etc.

Most local handles need to be nulled, as they leak.

Handle counters basically show you if your map is leaking handles or not.
If the count goes up constantly; chances are that your map leaks.
It'll go up when units are created, etc.

This is my Handle Counter. It shows the count, and how much it's increase/decreased in the past second.
JASS:
library HandleCounter initializer Init 
//  ________________________________________
// +----------------------------------------+
// |    H A N D L E   C O U N T E R   v1    |
// +----------------------------------------+
// |      By Romek - For his Demo Map       |
// |________________________________________|
// +----------------------------------------+

// Frankly, I don't care about the efficiency of a handle counter.
// Nor do I care about how well a temporary script is coded. <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite7" alt=":p" title="Stick Out Tongue    :p" loading="lazy" data-shortname=":p" />
    globals
        private leaderboard LB
        private location array Loc
        
        private constant integer DEC = 0x100000
        
        private integer Last = DEC * DEC
        private integer Curr = 0
        private integer Change = 0
    endglobals
    
    private struct T extends array
        static integer S = 0
        static integer M = 0
        static integer H = 0
        
        static string SS = &quot;00&quot;
        static string MS = &quot;00&quot;
        static string HS = &quot;00&quot;
    endstruct
    
    private function H2I takes handle h returns integer
        return h
        return 0
    endfunction
    
    private function Expire takes nothing returns nothing
        local integer i = 0
    
        set T.S = T.S + 1
        if T.S &gt; 60 then
            set T.S = 1
            set T.M = T.M + 1
            
            if T.M &gt;= 10 then
                set T.MS = I2S(T.M)
            else
                set T.MS = &quot;0&quot; + I2S(T.M)
            endif
        endif
        if T.M &gt; 60 then
            set T.M = 1
            set T.H = T.H + 1
            
            if T.H &gt;= 10 then
                set T.HS = I2S(T.H)
            else
                set T.HS = &quot;0&quot; + I2S(T.H)
            endif
        endif
        
        if T.S &gt;= 10 then
            set T.SS = I2S(T.S)
        else
            set T.SS = &quot;0&quot; + I2S(T.S)
        endif
        
        call LeaderboardSetItemLabel(LB, 2, &quot;                 &quot; + T.HS + &quot;:&quot; + T.MS + &quot;:&quot; + T.SS)
        
        loop
            set i = i + 1
            set Loc<i> = Location(0., 0.)
            exitwhen i == 100
        endloop
        set Curr = (H2I(Loc[100]) - DEC) - 100
        call LeaderboardSetItemValue(LB, 0, Curr)
        loop
            call RemoveLocation(Loc<i>)
            set Loc<i> = null
            set i = i - 1
            exitwhen i &lt; 0
        endloop
        
        set Change = Curr - Last
        set Last = Curr
        if Change &gt; 0 then
            call LeaderboardSetItemValue(LB, 1, Change)
            call LeaderboardSetItemValueColor(LB, 1, 0xFF, 0, 0, 0xFF)
        else
            call LeaderboardSetItemValue(LB, 1, Change)
            call LeaderboardSetItemValueColor(LB, 1, 0, 0xFF, 0, 0xFF)
        endif
    endfunction

    private function Start takes nothing returns nothing
        set LB = CreateLeaderboard()
        
        //call LeaderboardSetLabel(LB, &quot;       Handle Counter:&quot;)
        call LeaderboardSetLabel(LB, &quot;&quot;)
        call PlayerSetLeaderboard(GetLocalPlayer(), LB)
        call LeaderboardAddItem(LB, &quot;Handles:&quot;, 0, Player(15))
        call LeaderboardAddItem(LB, &quot;Change:&quot;, 0, Player(15))
        call LeaderboardAddItem(LB, &quot;                 00:00:00&quot;, 0, Player(15))
        
        // Colours of the LABELS
        call LeaderboardSetItemLabelColor(LB, 0, 0xFF, 0xDF, 0x00, 0xFF) // Handles
        call LeaderboardSetItemLabelColor(LB, 1, 0x00, 0xB7, 0xEB, 0xFF) // Changed
        call LeaderboardSetItemLabelColor(LB, 2, 0x77, 0x77, 0x77, 0xFF) // Time
        
        // Colours of the ITEMS. (Except &#039;Changed:&#039;)
        call LeaderboardSetItemValueColor(LB, 0, 0xFF, 0xFF, 0xFF, 0xFF)
        call LeaderboardSetItemValueColor(LB, 2, 13, 33, 37, 0) // Making the Time one invisible

        
        call LeaderboardSetSizeByItemCount(LB, 2)
        call LeaderboardDisplay(LB, true)
        
        call TimerStart(GetExpiredTimer(), 1., true, function Expire)
    endfunction

    private function Init takes nothing returns nothing
        call TimerStart(CreateTimer(), 0., false, function Start)
    endfunction
    
endlibrary</i></i></i>
 

Romek

Super Moderator
Reaction score
963
It shows how many handles you have in-game.
It can assist with showing you if you have handle leaks, yes.
It doesn't tell you what leaks, or where.

It's worth noting that the count will increase when non-leaking handles are created. So if you create a unit, for example, the count will go up.
If the count increases periodically and nothing visible is being created, then chances are, your map leaks.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top