HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

monsters spawn leak

04-21-2007, 08:45 PM#1
Sliderman
Hello everybody,
I have a trigger wich makes units spawn all the time. They move to a point and are removed when it's reached. This trigger looks for me perfect but it leaks anyway :/. Please help me.
Code:
function Trig_lvl6_Monsters_appear_top_Actions takes nothing returns nothing

    local unit troll
    local rect regAppear = gg_rct_lvl6_monster_appear_top
    local rect regDisappear = gg_rct_lvl6_monster_disappear_down
    local real minX = GetRectMinX( regAppear )
    local real maxX = GetRectMaxX( regAppear )
    local real randomX = GetRandomReal( minX, maxX )
    local real appearY = GetRectCenterY( regAppear )
    local real disappearY = GetRectCenterY( regDisappear )
    local real angle = 270
    local integer custVal = 1

    set troll = CreateUnit( Player(11), 'n000', randomX, appearY, angle )  
    call IssuePointOrder( troll, udg_move, randomX, disappearY )//udg_move contains "move"

    set troll = null        //////////////////
    set regAppear = null    //to avoid leaks//
    set regDisappear = null //////////////////
    
endfunction
    
    

//===========================================================================
function InitTrig_lvl6_Monsters_appear_top takes nothing returns nothing
    set gg_trg_lvl6_Monsters_appear_top = CreateTrigger(  )
    call DisableTrigger( gg_trg_lvl6_Monsters_appear_top )
    call TriggerRegisterTimerEventPeriodic( gg_trg_lvl6_Monsters_appear_top, 0.35 )
    call TriggerAddAction( gg_trg_lvl6_Monsters_appear_top, function Trig_lvl6_Monsters_appear_top_Actions )
endfunction
04-22-2007, 03:39 AM#2
Vexorian
Quote:
//udg_move contains "move"
why use a variable there?

Well nothing suspicious there besides the fact you are creating a unit each 0.35 seconds, so maybe the issue is with the code that removes the units?
04-22-2007, 08:59 AM#3
Sliderman
I use a variable because when you use a string, it leaks. (it's a little leak but a leak anyway) The string is created, then not removed. This way, it uses allways the same string.

This is how they disapear :
Code:
lvl6 Monsters from top disappear
    Evénements
        Unité - A unit enters lvl6 monster disappear down <gen>
    Conditions
        (Owner of (Triggering unit)) Egal Ã* Joueur 12 (Marron)
    Actions
        Unité - Remove (Triggering unit) from the game
I have to precise that 'lvl6_monster_appear_top' and 'lvl6_monster_disappear_down' have the same minX and maxX. So the units are all removed. I think that all information about a removed unit isn't deleted, because I don't see an other leak.
04-22-2007, 01:05 PM#4
Vexorian
Quote:
I use a variable because when you use a string, it leaks
No, that won't prevent a string leak.

Strings are always created and not removed but "move"=="move" it reuses the same string even if you don't use a variable.

--
And well, it doesn't seem to leak, it just lags because of the freaky amount of units to create. I guess you already tried disabling those triggers and the LAG stopped?

Also http://www.wc3campaigns.net/misc.php?do=bbcode#trigger and http://www.wc3campaigns.net/misc.php?do=bbcode#jass
04-22-2007, 03:02 PM#5
Sliderman
Quote:
Strings are always created and not removed but "move"=="move" it reuses the same string even if you don't use a variable.
Are you sure of this ?
How can the computer know that "move" has been used before ?

Quote:
And well, it doesn't seem to leak, it just lags because of the freaky amount of units to create. I guess you already tried disabling those triggers and the LAG stopped?
Did i say something about a lag ? I said it leaks. And there is no lag. I checked with ctrl + alt + del and war3.exe causes leaks. (25 kb/s) If the trigger is off, the leak is only 1kb/s....
04-22-2007, 03:22 PM#6
Vexorian
Quote:
Are you sure of this ?
How can the computer know that "move" has been used before ?
The computer doesn't know so but wc3 does, they just abuse hashes and stuff Jass strings are a mess.

...
An increase in memory usage is not necessarily a leak.
04-22-2007, 04:12 PM#7
Sliderman
Quote:
An increase in memory usage is not necessarily a leak.
??? I know......look, i turned on the trigger, then wait the first trolls to reach their remove point. Then the number of spawned trolls is supposed to stay constant because the distance they walk before being removed is the same for all. So the memory used by the trigger (or the spawned monsters) is supposed to stay constant, but there is a leak of 24kb/s (25-1). How I calculated the leak ? I noticed the memory used by war3.exe, waited 10 minutes, then look the new value. The new one less the old one is the leak every 10 minutes. So I divided by 60*10 = 600. I got the result : 25kb/s. But I looked with the trigger off too, where i got a leak of 1kb/s only. I am really talking about a memory leak, not about an "increase in memory usage"...
04-22-2007, 08:28 PM#8
Sliderman
What do you mean by "they just abuse hashes" ?

By the way, thx for the links about bbcodes.
04-23-2007, 04:46 AM#9
Sliderman
Every time I do Player(11), doesn't it cause a leak ? Shouldn't I create a local player variable that i set to Player(11), and then set to null at the end of the function ?

Here is the new version of my trigger, that still leaks :
Collapse JASS:
function Trig_lvl6_Monsters_appear_top_Actions takes nothing returns boolean

    local unit troll
    local rect regAppear = gg_rct_lvl6_monster_appear_top
    local rect regDisappear = gg_rct_lvl6_monster_disappear_down
    local real minX = GetRectMinX( regAppear )
    local real maxX = GetRectMaxX( regAppear )
    local real randomX = GetRandomReal( minX, maxX )
    local real appearY = GetRectCenterY( regAppear )
    local real disappearY = GetRectCenterY( regDisappear )
    local real angle = 270
    local integer custVal = 1
    local player P12 = Player(11)

    set troll = CreateUnit( P12, 'n000', randomX, appearY, angle )  
    call IssuePointOrder( troll, udg_move, randomX, disappearY )

    set troll = null
    set regAppear = null
    set regDisappear = null
    set P12 = null

    return false
    
endfunction
    
    

//===========================================================================
function InitTrig_lvl6_Monsters_appear_top takes nothing returns nothing
    set gg_trg_lvl6_Monsters_appear_top = CreateTrigger(  )
    call DisableTrigger( gg_trg_lvl6_Monsters_appear_top )
    call TriggerRegisterTimerEventPeriodic( gg_trg_lvl6_Monsters_appear_top, 0.35 )
    call TriggerAddCondition( gg_trg_lvl6_Monsters_appear_top, Condition(function Trig_lvl6_Monsters_appear_top_Actions ))
endfunction
04-23-2007, 08:25 AM#10
Toadcop
ok the time is here to open your eyes =) there is no serious problems with our code ! the problem is what war3 does not clear fully unit's from memory thats all =) so it will need more and more and more and more memory =) but the leaks are not so great so you can ignore it...

// you can test it for example with trigger like this but with a less period... (use SetUnitPathing(unit,false))
04-23-2007, 08:30 PM#11
Sliderman
It's quite a big problem -.- Is there no way to remove units totally ?
What is SetUnitPathing for ?
04-23-2007, 08:49 PM#12
Toadcop
Quote:
Is there no way to remove units totally
- NO
Vex may say it's not true but it's true ! =)