1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. The Lich King demands your service! We've reached the 19th edition of the Icon Contest. Come along and make some chilling servants for the one true king.
    Dismiss Notice
  4. The 4th SFX Contest has started. Be sure to participate and have a fun factor in it.
    Dismiss Notice
  5. The poll for the 21st Terraining Contest is LIVE. Be sure to check out the entries and vote for one.
    Dismiss Notice
  6. The results are out! Check them out.
    Dismiss Notice
  7. Don’t forget to sign up for the Hive Cup. There’s a 555 EUR prize pool. Sign up now!
    Dismiss Notice
  8. The Hive Workshop Cup contest results have been announced! See the maps that'll be featured in the Hive Workshop Cup tournament!
    Dismiss Notice
  9. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

CreateUnit Leaks a Point?

Discussion in 'World Editor Help Zone' started by aple, Mar 2, 2017.

  1. aple

    aple

    Joined:
    May 20, 2009
    Messages:
    807
    Resources:
    2
    Maps:
    1
    Tutorials:
    1
    Resources:
    2
    It would appear so, can anyone confirm this?
     
  2. Dr Super Good

    Dr Super Good

    Spell Reviewer

    Joined:
    Jan 18, 2005
    Messages:
    25,596
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    Code (vJASS):
    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

    Code (vJASS):
    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

    Code (vJASS):
    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

    Code (vJASS):
    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.
     
  3. aple

    aple

    Joined:
    May 20, 2009
    Messages:
    807
    Resources:
    2
    Maps:
    1
    Tutorials:
    1
    Resources:
    2
    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.
     
  4. Dr Super Good

    Dr Super Good

    Spell Reviewer

    Joined:
    Jan 18, 2005
    Messages:
    25,596
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    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.
     
  5. aple

    aple

    Joined:
    May 20, 2009
    Messages:
    807
    Resources:
    2
    Maps:
    1
    Tutorials:
    1
    Resources:
    2
    Okay, so any difference I've seen by moving over to CreateUnitAtLoc is a placebo effect then.
     
  6. Dr Super Good

    Dr Super Good

    Spell Reviewer

    Joined:
    Jan 18, 2005
    Messages:
    25,596
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    CreateUnitAtLoc executes faster as it has to pass 1 less parameter. However for the speed difference to be apparent you will already be creating far too many units per second.
     
  7. aple

    aple

    Joined:
    May 20, 2009
    Messages:
    807
    Resources:
    2
    Maps:
    1
    Tutorials:
    1
    Resources:
    2
    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.
     
  8. EdgeOfChaos

    EdgeOfChaos

    Joined:
    Jan 8, 2014
    Messages:
    639
    Resources:
    1
    Tutorials:
    1
    Resources:
    1
    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.