HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Multiboard,string memory leak?

12-08-2004, 03:33 AM#1
Mjukland
Why does this trigger leak ?

Code:
function Trig_MultiBoard_Laps_Update_Actions takes nothing returns nothing

    local string stotal
    set udg_RealTotalTime = ( udg_RealTotalTime + 0.01 )
    set stotal = R2SW((udg_RealTotalTime),1,2)
    call MultiboardSetItemValueBJ( udg_CarsMultiBoardLaps, 6, 2, stotal )
    set stotal = null

endfunction

//===========================================================================
function InitTrig_MultiBoard_Laps_Update takes nothing returns nothing
    set gg_trg_MultiBoard_Laps_Update = CreateTrigger(  )
    call DisableTrigger( gg_trg_MultiBoard_Laps_Update )
    call TriggerRegisterTimerEventPeriodic( gg_trg_MultiBoard_Laps_Update, 0.01 )
    call TriggerAddAction( gg_trg_MultiBoard_Laps_Update, function Trig_MultiBoard_Laps_Update_Actions )
endfunction
12-08-2004, 01:28 PM#2
AIAndy
Strings are a bit strange in Warcraft. Every string literal that is used is entered in a string table and from then on referenced by that id.
An example:
local string s = "Hello" // Add "Hello" to string table, put the reference to it in s
local string t = "Hello" // Check if "Hello" is in string table. It is, so the same reference as is in s will be put in t

That has the advantage that a string comparison can be done by just comparing the references. But it also has the big disadvantage that the more string literals you use, the more entries are put in the string table, independant of the number of string variables you use.
Example:
local integer i = 0
local string s
loop
exitwhen i > 20000
set s = I2S(i)
set i = i + 1
endloop

This will make the string table grow by 20000 entries and there is no way to get it smaller again. That are not real leaks but they can be a problem. Doing the loop again will not make the string table grow as all entries are already there.
12-08-2004, 02:07 PM#3
Mjukland
Oh, ok, thanks for pointing that out.

Then there is no way to do a timer that counts every 0.01 second without getting massive memory loss over time?

ofcourse I don't need to have a timer that counts every 0.01 second, its for a racing mod so the timer would be nice, well, I'll use a counter that counts every second instead, and then just have the exact timing when you've made a lap.

thanks.