• 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] Where is memory leak?

Status
Not open for further replies.
Level 3
Joined
Jun 16, 2005
Messages
36
Here are 'standard' Return Bug/ Super Custom Value functions.
JASS:
function HandleToIntegerRB takes handle h returns integer
return h
return 0
endfunction

function ReturnEffectRB takes integer i returns effect
return i
return null
endfunction

function LoadValueSCV takes handle h, string key returns integer
return GetStoredInteger(udg_cache, I2S(HandleToIntegerRB(h)), key)
endfunction

function LoadEffectSCV takes handle h, string key returns effect
return ReturnEffectRB(GetStoredInteger(udg_cache, I2S(HandleToIntegerRB(h)), key))
endfunction

function FlushObjectSCV takes handle h returns nothing
call FlushStoredMission(udg_cache, I2S(HandleToIntegerRB(h)))
endfunction

function StoreObjectSCV takes handle h, string key, integer val returns nothing
call StoreInteger(udg_cache, I2S(HandleToIntegerRB(h)), key, val)
endfunction

This two functions were made to easier effect destruction. The idea is to make a function, which creates a trigger for effect to be destructed.
JASS:
function DEA takes nothing returns nothing
local trigger t = GetTriggeringTrigger()
local effect e = LoadEffectSCV(t, "sp_effect")
local integer i = LoadValueSCV(t, "time")
call PolledWait(i)
call DestroyEffect(e)
set e = null
set i = 0
call DestroyTrigger(t)
set t = null
call FlushObjectSCV(t)
endfunction

function DestroyEffectSCV takes effect e, integer t returns nothing
local trigger trig
set trig = CreateTrigger(  )
call StoreObjectSCV(trig, "sp_effect", HandleToIntegerRB(e) )
call StoreObjectSCV(trig, "time", t)
call TriggerAddAction( trig, function DEA)
endfunction
But somwhere there is a leak. :( How can I avoid it?
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
Its here
function DEA takes nothing returns nothing
local trigger t = GetTriggeringTrigger()
local effect e = LoadEffectSCV(t, "sp_effect")
local integer i = LoadValueSCV(t, "time")
call PolledWait(i)
call DestroyEffect(e)
set e = null
set i = 0
call DestroyTrigger(t)
set t = null
//LEAK_START
call FlushObjectSCV(t)
//LEAK_END
endfunction

Your ordering it to flush nothing since you destroyed the trigger and the variable so your flushing null not your trigger.
It should look like this.

//CORECTION_START
function DEA takes nothing returns nothing
local trigger t = GetTriggeringTrigger()
local effect e = LoadEffectSCV(t, "sp_effect")
local integer i = LoadValueSCV(t, "time")
call PolledWait(i)
call FlushObjectSCV(t)
call DestroyEffect(e)
call DestroyTrigger(t)
set e = null
set t = null
set i = 0
endfunction
//CORECTION_END

That should not leak.
 
Status
Not open for further replies.
Top