• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] Destructable "Memory Leaks"

Status
Not open for further replies.
Level 1
Joined
May 10, 2012
Messages
5
Good day!

The problem with the script, tried every possible way to solve it.

Take a look

JASS:
function Trig_WoodCreateTest_Actions takes nothing returns nothing
    local real L_Tree_X = 0.0
    local real L_Tree_Y = 0.0
    local real L_TreeFacing = 0.0
    local destructable L_TMP = null

        set bj_forLoopAIndex = 1
        set bj_forLoopAIndexEnd = 100000
        loop
            exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
            
            set L_Tree_X = GetRandomReal(GetRectMinX(udg_PlayableMapArea), GetRectMaxX(udg_PlayableMapArea))
            set L_Tree_Y = GetRandomReal(GetRectMinY(udg_PlayableMapArea), GetRectMaxY(udg_PlayableMapArea))
            set L_TreeFacing = GetRandomReal(0, 360)

            set L_TMP = CreateDestructable('LTlt', L_Tree_X, L_Tree_Y, L_TreeFacing, 1, 0)
            set L_TMP = null
            
            set bj_forLoopAIndex = bj_forLoopAIndex + 1
        endloop
endfunction

//===========================================================================
function InitTrig_WoodCreateTest takes nothing returns nothing
    set gg_trg_WoodCreateTest = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_WoodCreateTest, 2.00 )
    call TriggerRegisterPlayerChatEvent( gg_trg_WoodCreateTest, Player(0), "create", true )
    call TriggerAddAction( gg_trg_WoodCreateTest, function Trig_WoodCreateTest_Actions )
endfunction

P.S // L_TMP - paraynoya

JASS:
function Trig_WoodDie_Func002A takes nothing returns nothing
    local destructable L_TMP = null
    set L_TMP = GetEnumDestructable() 
        call RemoveDestructable(L_TMP)
    set L_TMP = null
endfunction

function Trig_WoodDie_Actions takes nothing returns nothing
    call EnumDestructablesInRectAll( udg_PlayableMapArea, function Trig_WoodDie_Func002A )
endfunction

//===========================================================================
function InitTrig_WoodDie takes nothing returns nothing
    set gg_trg_WoodDie = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_WoodDie, 1.50 )
    call TriggerAddAction( gg_trg_WoodDie, function Trig_WoodDie_Actions )
endfunction

P.S // L_TMP - paraynoya
// udg_PlayableMapArea - predefined rect

It works fine, but causes a memory leak. 120 mb, 200, 300, 400, crash...
I've tried everything, a memory leak continues.
 
Level 1
Joined
May 10, 2012
Messages
5
bj_forLoopAIndexEnd is leaking? Many? Why?

100000 iterations, a little bit.

This code, I found the leak. Under normal circumstances, memory is allocated for the object "tree", after the removal of the object "tree", the memory must be freed, but this does not happen.

How do I clear memory?

IMHO Jass full of holes like a post-apocalyptic ship. And we all patches leaks and holes. xD

Damn, I wish a lot of trees! I want to do 100,000 trees per second and destroy 100,000 trees per second, but there is a slight problem.
I have a similar code for special effects and it does not leak, even though there is something similar. And 100,000 of special effects is fine =)

JASS:
function Trig_Trees_Actions takes nothing returns nothing
    local real L_Tree_X = 0.0
    local real L_Tree_Y = 0.0
    local real L_TreeFacing = 0.0
    local destructable L_TMP = null

        set bj_forLoopAIndex = 1
        set bj_forLoopAIndexEnd = 100000
        loop
            exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
            
            set L_Tree_X = GetRandomReal(GetRectMinX(udg_PlayableMapArea), GetRectMaxX(udg_PlayableMapArea))
            set L_Tree_Y = GetRandomReal(GetRectMinY(udg_PlayableMapArea), GetRectMaxY(udg_PlayableMapArea))
            set L_TreeFacing = GetRandomReal(0, 360)

            set L_TMP = CreateDestructable('LTlt', L_Tree_X, L_Tree_Y, L_TreeFacing, 1, 0)
            call RemoveDestructable(L_TMP)
            set L_TMP = null
            
            set bj_forLoopAIndex = bj_forLoopAIndex + 1
        endloop

endfunction

//===========================================================================
function InitTrig_Trees takes nothing returns nothing
    set gg_trg_Trees = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_Trees, 2.00 )
    call TriggerAddAction( gg_trg_Trees, function Trig_Trees_Actions )
endfunction

It also causes leakage

JASS:
function Trig_Trees_Actions takes nothing returns nothing
    local real L_Tree_X = 0.0
    local real L_Tree_Y = 0.0
    local real L_TreeFacing = 0.0

        set bj_forLoopAIndex = 1
        set bj_forLoopAIndexEnd = 100000
        loop
            exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
            
            set L_Tree_X = GetRandomReal(GetRectMinX(udg_PlayableMapArea), GetRectMaxX(udg_PlayableMapArea))
            set L_Tree_Y = GetRandomReal(GetRectMinY(udg_PlayableMapArea), GetRectMaxY(udg_PlayableMapArea))
            set L_TreeFacing = GetRandomReal(0, 360)

            set bj_forLoopAIndex = bj_forLoopAIndex + 1
        endloop

endfunction

//===========================================================================
function InitTrig_Trees takes nothing returns nothing
    set gg_trg_Trees = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_Trees, 2.00 )
    call TriggerAddAction( gg_trg_Trees, function Trig_Trees_Actions )
endfunction

All is fine, no leaks.

JASS:
function Trig_Trees_Actions takes nothing returns nothing
    local real L_Tree_X = 0.0
    local real L_Tree_Y = 0.0
    local real L_TreeFacing = 0.0
    local destructable L_TMP = null

        set bj_forLoopAIndex = 1
        set bj_forLoopAIndexEnd = 100000
        loop
            exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
            
            set L_Tree_X = GetRandomReal(GetRectMinX(udg_PlayableMapArea), GetRectMaxX(udg_PlayableMapArea))
            set L_Tree_Y = GetRandomReal(GetRectMinY(udg_PlayableMapArea), GetRectMaxY(udg_PlayableMapArea))
            set L_TreeFacing = GetRandomReal(0, 360)

            call CreateDestructable('LTlt', L_Tree_X, L_Tree_Y, L_TreeFacing, 1, 0)
            
            set bj_forLoopAIndex = bj_forLoopAIndex + 1
        endloop

endfunction

//===========================================================================
function InitTrig_Trees takes nothing returns nothing
    set gg_trg_Trees = CreateTrigger(  )
    call TriggerRegisterTimerEventSingle( gg_trg_Trees, 1.00 )
    call TriggerAddAction( gg_trg_Trees, function Trig_Trees_Actions )
endfunction


function Trig_WoodDie_Func002A takes nothing returns nothing
    call DoNothing()
endfunction

function Trig_WoodDie_Actions takes nothing returns nothing
    call DisplayTextToForce( GetPlayersAll(), "Iteration" )
    call EnumDestructablesInRectAll( udg_PlayableMapArea, function Trig_WoodDie_Func002A )
endfunction

//===========================================================================
function InitTrig_WoodDie takes nothing returns nothing
    set gg_trg_WoodDie = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_WoodDie, 1.50 )
    call TriggerAddAction( gg_trg_WoodDie, function Trig_WoodDie_Actions )
endfunction

All is fine, no leaks. The functions of EnumDestructablesInRectAll no leaks


In theory, a conclusion native function CreateDestructable leads to leaks. Sadly, it is too difficult to analyze the function itself without having the source code in C
 
Last edited:
leak==lag or frame drops or memory usage up, whatever you call it it's the same...

your EnumDestructablesInRectAll doesnt leak coz it does nothing and GetPlayersAll() doesnt leak either...

your Trig_Trees_Actions call reals, so doesnt leak...

the other Trig_Trees_Actions creates 100K destructables every 2 seconds, which is very bad,
even if you remove it still there's a small memory usage at hand...
 
Level 1
Joined
May 10, 2012
Messages
5
even if you remove it still there's a small memory usage at hand...

Is not true. I agree that in this example 100k trees is bad. At the time of their creation will be micro-lag. In reality, I create on a tree in 0.10 seconds. But at this rate I'll have to spend 2 hours to see a memory leak.

When you create a 100k trees allocate 20 megabytes of RAM. When you remove the trees, the memory is not cleared. Perhaps it is an internal optimization engine to relocate objects in memory. Since the allocation of memory segment, continuous operation. But if you create and remove trees in the cycle, the memory begins to grow, leading to a fatal error. It is the leak.

For example, I create and remove the effects of 1000 per second. Tested within an hour, found no leaks. But with the destructible, discovered a memory leak.
 
1) You can't loop 1-100000 here, it is impossible with your setup. You need to do multi-threading to make this possible. Currently your thing will crash the thread once you get 1000 or 2000 destructables and that's all you're creating. No more.

2) Units leave traces of memory even after removed, it appears the same for destructables. No new information here. Blizzard knows about the unit leak but as far as they are concerned this is an 11 year old game and they simply don't have the money to spend to hire people to fix the source.

Maybe we can do a kickstarter project to get Blizzard to fix the mistakes in the WC3 engine. Maybe they only care about StarCraft 2 at this point. For now, we are left with the current state of things and must accept that or move on.

3) What the heck are you doing trying to create so many trees and remove them right afterward? No one's computer can handle that without lagging when you create/remove the trees, so forget it. Really bad idea.
 
Level 1
Joined
May 10, 2012
Messages
5
You can't loop 1-100000 here, it is impossible with your setup. You need to do multi-threading to make this possible. Currently your thing will crash the thread once you get 1000 or 2000 destructables and that's all you're creating. No more.

My code works fine, the only thing that creates a micro-frieze 0.2 seconds on my i7 extreme 5 ghz =)

Units leave traces of memory even after removed, it appears the same for destructables. No new information here.

Yes, exactly. (Blizzard, apparently made ​​a mistake.)

Dunno what you want do achieve but creating and destroying 100.000 things at same time won't get you far >.>

To detect memory leaks. Otherwise, it will take more than 40 minutes. If trees are created slowly.


The conclusion:

The error in the game engine, which leads to memory leaks. Remedy problems - NO.

Question closed. Blizzard sucks.
 
Status
Not open for further replies.
Top