HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Memory Leak while just using local variables

11-19-2002, 08:37 PM#1
SuperIKI
Code:
function localv takes nothing returns location
    local location r=Location(1.0,2.0)
    return r
endfunction

function Trig_Untitled_Trigger_002_Actions takes nothing returns nothing
    local integer i=0
    local location l
    loop
        exitwhen i==700
        set l=localv()
        call RemoveLocation(l)
        set i=i+1
    endloop
endfunction

//===========================================================================
function InitTrig_Untitled_Trigger_002 takes nothing returns nothing
    set gg_trg_Untitled_Trigger_002 = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_Untitled_Trigger_002, 0.1 )
    call TriggerAddAction( gg_trg_Untitled_Trigger_002, function Trig_Untitled_Trigger_002_Actions )
endfunction

What is this??? A memory leak.
Import this trigger into your map and it will only last one minute until it gets stuck.
But what does this trigger do? Nothing. It doesn't even seem to be a memory leak.
:(

This is no question. It is absolutely clear that the location objects aren't deleted from memory. I did a lot of testing on this.
Either RemoveLocation doesn't free memory or return values are saved separate and not deleted.

I liked JASS, I really did.
11-20-2002, 12:31 AM#2
Guest
Try raising the periodicity. It may simply be doing something like a stack overflow because it's queuing up too many triggers (10 per second).

Just a thought.
11-20-2002, 06:27 AM#3
SuperIKI
Quote:
Originally posted by Heaven
Try raising the periodicity. It may simply be doing something like a stack overflow because it's queuing up too many triggers (10 per second).

Just a thought.

No, the triggers don't stack with that periodicity. I tried it with outputs on the screen on the first and on the last line of the function.
11-20-2002, 08:54 AM#4
Guest
I duplicated your efforts, and got the same results. After close to a minute of elapsed time I could notice the framerate dropping.

Hmm.

At 7,000 locations per second, after about 50 seconds we've created 350,000 locations. I doubt if it's memory that's at issue here, but simple processing speed. I bet that the game engine has to iterate through all those locations every so often, like when you scroll the map or something. That would explain the framerate drop. After about a minute, if I hit F10 to exit the map the framerate shoots back up to normal while the dialog box is displayed.

It would be nice to know why RemoveLocation doesn't in fact entirely remove the location.

On a possibly related note, I just modified the function to create a unit, display it's x/y, life and mana, kill it, then display it again. I repeated this for removal and explosion. In all cases the x/y was still readable afterwards, and in the case of killing and exploding the unit's life was 0. With removal nothing seemed to change. This limited test seems to bear out Weeaddar's assumption that removal equates with hiding.

More tests are warranted of course.

Care.