HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Where's the Memory Leaks?

02-02-2005, 07:06 PM#1
oNdizZ
I run this codes through the Memory Leak Indicator and i got 6 leaks, but i can't see any1, i thought i had fixed them :S
Anyway, if you see any leak, please let me now.
Here's the Code:

Code:
function Trig_Chaos_Bats_Jass_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A000' ) ) then
        return false
    endif
    return true
endfunction

function Trig_Chaos_Bats_Jass_Actions takes nothing returns nothing
    local location CasterPoint
    local location SpawnPoint
    set CasterPoint = GetUnitLoc(GetSpellAbilityUnit())
    set bj_forLoopAIndex = 1
    set bj_forLoopAIndexEnd = ( 5 + ( GetUnitAbilityLevelSwapped(GetSpellAbilityId(), GetSpellAbilityUnit()) * 2 ) )
    loop
        exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
        set SpawnPoint = PolarProjectionBJ( CasterPoint, ( 300.00 + ( I2R(GetUnitAbilityLevelSwapped(GetSpellAbilityId(), GetSpellAbilityUnit())) * 150.00 ) ), ( I2R(GetForLoopIndexA()) * ( 360.00 / ( 5.00 + ( I2R(GetUnitAbilityLevelSwapped(GetSpellAbilityId(), GetSpellAbilityUnit())) * 2.00 ) ) ) ))
        call CreateNUnitsAtLoc( 1, 'h000', GetOwningPlayer(GetSpellAbilityUnit()), SpawnPoint, bj_UNIT_FACING )
        call ShowUnitHide( GetLastCreatedUnit() )
        call UnitAddAbilityBJ( 'AUcs', GetLastCreatedUnit() )
        call SetUnitAbilityLevelSwapped( 'AUcs', GetLastCreatedUnit(), GetUnitAbilityLevelSwapped('A000', GetSpellAbilityUnit()) )
        call IssuePointOrderLocBJ( GetLastCreatedUnit(), "carrionswarm", CasterPoint )
        call UnitApplyTimedLifeBJ( 1.00, 'BTLF', GetLastCreatedUnit() )
        call RemoveLocation( SpawnPoint )
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop
    call RemoveLocation( CasterPoint )
    set CasterPoint = null
    set SpawnPoint = null
endfunction

//===========================================================================
function InitTrig_Chaos_Bats_Jass takes nothing returns nothing
    set gg_trg_Chaos_Bats_Jass = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Chaos_Bats_Jass, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Chaos_Bats_Jass, Condition( function Trig_Chaos_Bats_Jass_Conditions ) )
    call TriggerAddAction( gg_trg_Chaos_Bats_Jass, function Trig_Chaos_Bats_Jass_Actions )
endfunction
02-03-2005, 06:30 AM#2
SentryIII
Well since no one's responsing, I might as well.

There are no leaks as far as I can tell. That Memory Leak Indicator is probably incorrect. But I am sorta wondering why you're setting your local points to null after they've been destroyed. If those variables point to nothing, isn't it still considered null?
02-03-2005, 03:11 PM#3
oNdizZ
Dunno, I blame everything on toot ;) ;) ;) he told me to do so, and to set it to null will probably help some(?)
02-03-2005, 08:32 PM#4
curi
well handle variables (like locations) really hold like a pointer to the object, not the object itself. so destroying the object could leave a junk pointer to nowhere depending how Blizzard coded it. and making the variable null might, depending what Blizzard did, get the memory cleanup to work right. I've heard people claiming that setting stuff to null helps with leaks, I haven't tested myself though.
02-04-2005, 04:39 AM#5
SentryIII
I've never had problems with leaks since I worked on Battleship Command. My theory is that pointers are basically native data types that contain the address of a memory location as an integer or string (something like 0x7a4b, etc.). So what happens to local integers and strings at the end of a function? Well it doesn't stay in memory, thats for sure.

So that's my theory, and I'm sticking by it. That is, until someone proves it otherwise. :)
02-04-2005, 07:20 AM#6
Tabris
nothing with memory leak but
function Trig_Chaos_Bats_Jass_Conditions takes nothing returns boolean
if ( not ( GetSpellAbilityId() == 'A000' ) ) then
return false
endif
return true
endfunction

only use
function Trig_Chaos_Bats_Jass_Conditions takes nothing returns boolean
return GetSpellAbilityId() == 'A000'
endfunction
is good no?
02-07-2005, 01:05 PM#7
Mjukland
Everytime you use a "Get" function it will leak. GetLastCreatedUnit, GetSpellAbilityId, though you don't have to care about abilities... just fix the unit functions. Something like this:

Code:
function Trig_Chaos_Bats_Jass_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A000' ) ) then
        return false
    endif
    return true
endfunction

function Trig_Chaos_Bats_Jass_Actions takes nothing returns nothing
    local location CasterPoint
    local location SpawnPoint
    local unit TempUnit
    set CasterPoint = GetUnitLoc(GetSpellAbilityUnit())
    set bj_forLoopAIndex = 1
    set bj_forLoopAIndexEnd = ( 5 + ( GetUnitAbilityLevelSwapped(GetSpellAbilityId(), GetSpellAbilityUnit()) * 2 ) )
    loop
        exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
        set SpawnPoint = PolarProjectionBJ( CasterPoint, ( 300.00 + ( I2R(GetUnitAbilityLevelSwapped(GetSpellAbilityId(), GetSpellAbilityUnit())) * 150.00 ) ), ( I2R(GetForLoopIndexA()) * ( 360.00 / ( 5.00 + ( I2R(GetUnitAbilityLevelSwapped(GetSpellAbilityId(), GetSpellAbilityUnit())) * 2.00 ) ) ) ))
        call CreateNUnitsAtLoc( 1, 'h000', GetOwningPlayer(GetSpellAbilityUnit()), SpawnPoint, bj_UNIT_FACING )
        set TempUnit = GetLastCreatedUnit() 
        call ShowUnitHide( TempUnit )
        call UnitAddAbilityBJ( 'AUcs', TempUnit )
        call SetUnitAbilityLevelSwapped( 'AUcs', TempUnit, GetUnitAbilityLevelSwapped('A000', GetSpellAbilityUnit()) )
        call IssuePointOrderLocBJ( TempUnit, "carrionswarm", CasterPoint )
        call UnitApplyTimedLifeBJ( 1.00, 'BTLF', TempUnit)
        call RemoveLocation( SpawnPoint )
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop
    call RemoveLocation( CasterPoint )
    set TempUnit = null
    set CasterPoint = null
    set SpawnPoint = null
endfunction

//===========================================================================
function InitTrig_Chaos_Bats_Jass takes nothing returns nothing
    set gg_trg_Chaos_Bats_Jass = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Chaos_Bats_Jass, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Chaos_Bats_Jass, Condition( function Trig_Chaos_Bats_Jass_Conditions ) )
    call TriggerAddAction( gg_trg_Chaos_Bats_Jass, function Trig_Chaos_Bats_Jass_Actions )
endfunction
[/quote]
02-07-2005, 04:41 PM#8
curi
umm, creating a variable, setting something to it, and nulling the variable won't fix anything. if there was a leak, it'd still be there, b/c you never destroy the something. but the something is a unit that shouldn't be destroyed anyway...
02-07-2005, 06:55 PM#9
SentryIII
GetLastCreatedUnit() doesn't leak. All it does is returns the unit that was created (which is now on the map, so it can be referenced in several different ways.
02-07-2005, 08:55 PM#10
Vexorian
Quote:
Everytime you use a "Get" function it will leak. GetLastCreatedUnit, GetSpellAbilityId, though you don't have to care about abilities... just fix the unit functions. Something like this:
That's not true, it depends more of what the function does rather than the name, GetOwningPlayer doesn't leak, I actually don't remember of any function that starts with Get and leaks at this time