• 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.
  • Create a faction for Warcraft 3 and enter Hive's 19th Techtree Contest: Co-Op Commanders! Click here to enter!
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 21st Texturing Contest: Upgrade is now concluded, time to vote for your favourite set of icons! Click here to vote!

CreateUnit Leaks a Point?

Status
Not open for further replies.

Dr Super Good

Spell Reviewer
Level 65
Joined
Jan 18, 2005
Messages
27,296
JASS:
function CreateUnitAtLocSaveLast takes player id,integer unitid,location loc,real face returns unit
    if (unitid == 'ugol') then
        set bj_lastCreatedUnit = CreateBlightedGoldmine(id, GetLocationX(loc), GetLocationY(loc), face)
    else
        set bj_lastCreatedUnit = CreateUnitAtLoc(id, unitid, loc, face)
    endif
    return bj_lastCreatedUnit
endfunction
JASS:
function CreateNUnitsAtLoc takes integer count,integer unitId,player whichPlayer,location loc,real face returns group
    call GroupClear(bj_lastCreatedGroup)
    loop
        set count = count - 1
        exitwhen count < 0
        call CreateUnitAtLocSaveLast(whichPlayer, unitId, loc, face)
        call GroupAddUnit(bj_lastCreatedGroup, bj_lastCreatedUnit)
    endloop
    return bj_lastCreatedGroup
endfunction
JASS:
function CreateNUnitsAtLocFacingLocBJ takes integer count,integer unitId,player whichPlayer,location loc,location lookAt returns group
    return CreateNUnitsAtLoc(count, unitId, whichPlayer, loc, AngleBetweenPoints(loc, lookAt))
endfunction
JASS:
function AngleBetweenPoints takes location locA,location locB returns real
    return bj_RADTODEG * Atan2(GetLocationY(locB) - GetLocationY(locA), GetLocationX(locB) - GetLocationX(locA))
endfunction
I do not see it leaking a location object internally...

Obviously if you leak the location object you pass to it by not removing the location after the end of its useful life then that location object will leak. But in any case that is not the fault of the create unit action.
 
Level 12
Joined
May 20, 2009
Messages
822
CreateUnit, the native. Takes an X, Y, Player ID, and a unit ID. It's none of those. It's not in Blizzard.j or Common.j so that's why I'm asking if anybody knows for sure or not. I'm wondering if internally it's taking that X and Y you feed it and creating a point with it but not actually removing the point afterwords.
 

Dr Super Good

Spell Reviewer
Level 65
Joined
Jan 18, 2005
Messages
27,296
CreateUnit, the native. Takes an X, Y, Player ID, and a unit ID. It's none of those. It's not in Blizzard.j or Common.j so that's why I'm asking if anybody knows for sure or not. I'm wondering if internally it's taking that X and Y you feed it and creating a point with it but not actually removing the point afterwords.
It is a native. Chances are what it does with the values have nothing to do with JASS.

I remember testing CreateUnit, monitoring handle IDs and such. The only increase in handle id it causes is the unit itself. The unit created seems to permanently increase memory consumption however I think that is an internal memory leak in WC3 and affects all units ever made (even ones made by structures and summons). The unit memoy leak might also be subject to garbage collection and even have been patched for all I know. However it has no complexity so will not cause lag.
 
Level 12
Joined
May 20, 2009
Messages
822
It wasn't necessarily a speed difference I thought I saw, it was a slowdown difference. Something in the code in my map was leaking like hell, and I found what I thought was a point-leak as the CreateUnits was just taking X of mypoint and Y of mypoint. I changed it to CreateUnitAtLoc and fed it my point and destroyed my point afterwords and there was no more noticeable slowdowns. I was already destroying my point before-hand, though, and there was still noticeable slowdowns. I changed it and then there was not.
 

EdgeOfChaos

E

EdgeOfChaos

I'm certain that CreateUnit does not leak a location, just from experience (and because that implementation would make no sense). But if you want to test it - make a test map where you create units and then remove them using both methods, and add the HandleCounter lib to it to count the leaks.
 
Status
Not open for further replies.
Top