- Joined
- Oct 23, 2011
- Messages
- 182
My map has been having a lot of fatal errors due to 'out of memory' errors, and I traced the issue down to a single line of JASS code (in a unit indexing system) that looks something like this:
My map's memory usage increases tremendously as units die when I have a single line of above JASS code.
The above example shouldn't even be doing anything because filter func is null.
Here's a simple example I used to test this issue on a test map
Respawn System to remake dummies
Any insights on this issue?
JASS:
call TriggerRegisterPlayerUnitEvent(CreateTrigger(), Player(12), EVENT_PLAYER_UNIT_ISSUED_ORDER, null)
My map's memory usage increases tremendously as units die when I have a single line of above JASS code.
The above example shouldn't even be doing anything because filter func is null.
Here's a simple example I used to test this issue on a test map
JASS:
scope Test
native UnitAlive takes unit u returns boolean
struct Test extends array
static group G = null
static method x takes nothing returns nothing
local unit u
call GroupEnumUnitsInRect(G, WorldBounds.world, null)
loop
set u = FirstOfGroup(G)
exitwhen u == null
call GroupRemoveUnit(G, u)
if GetUnitTypeId(u) == 'h000' and UnitAlive(u) then
call KillUnit(u)
endif
endloop
set u = null
endmethod
static method onInit takes nothing returns nothing
set G = CreateGroup()
// having this line causes HUGE memory leak!
call TriggerRegisterPlayerUnitEvent(CreateTrigger(), Player(12), EVENT_PLAYER_UNIT_ISSUED_ORDER, null)
call TimerStart(CreateTimer(), 0.2, true, function thistype.x)
endmethod
endstruct
endscope
Respawn System to remake dummies
JASS:
scope Respawn initializer OnInit
private struct Data extends array
implement Alloc
real x
real y
endstruct
private function OnExpiration takes nothing returns nothing
local Data data = ReleaseTimer(GetExpiredTimer())
call CreateUnit(Player(12), 'h000', data.x, data.y, 0)
call data.deallocate()
endfunction
private function OnDeath takes nothing returns boolean
local unit u = GetTriggerUnit()
local Data data
if GetUnitTypeId(u) == 'h000' then
set data = Data.allocate()
set data.x = GetUnitX(u)
set data.y = GetUnitY(u)
call TimerStart(NewTimerEx(data), 0.1, false, function OnExpiration)
endif
set u = null
return false
endfunction
private function OnInit takes nothing returns nothing
local trigger trg = CreateTrigger()
call TriggerRegisterPlayerUnitEvent(trg, Player(12), EVENT_PLAYER_UNIT_DEATH, null)
call TriggerAddCondition(trg, Condition(function OnDeath))
endfunction
endscope
Any insights on this issue?
Last edited: