trying to fix leaks

Grundy

Ultra Cool Member
Reaction score
35
i have never cared about memory leaks before, but im making a new awesome map so i really do not want any memory leaks. can someone take a look at this and tell if you see any leaks in it

Code:
toxic breath
    Events
        Unit - A unit Starts the effect of an ability
    Conditions
        (Ability being cast) Equal to Toxic Breath (Breath of Fire (Neutral Hostile))
    Actions
        Custom script:   local unit disease1
        Custom script:   local unit disease2
        Custom script:   local unit disease3
        Custom script:   local location targetloc = GetSpellTargetLoc()
        Custom script:   local location unitlocation = PolarProjectionBJ(GetUnitLoc(GetSpellAbilityUnit()), 75.00, AngleBetweenPoints(GetUnitLoc(GetSpellAbilityUnit()), targetloc))
        Custom script:   local location movepoint = PolarProjectionBJ( unitlocation, 256, AngleBetweenPoints(unitlocation, targetloc))
        Custom script:   call CreateNUnitsAtLoc( 1, 'e000', GetOwningPlayer(GetSpellAbilityUnit()), unitlocation, bj_UNIT_FACING )
        Custom script:   set disease1 = GetLastCreatedUnit()
        Custom script:   call SetUnitPathing( disease1, false )
        Custom script:   call CreateNUnitsAtLoc( 1, 'e000', GetOwningPlayer(GetSpellAbilityUnit()), unitlocation, bj_UNIT_FACING )
        Custom script:   set disease2 = GetLastCreatedUnit()
        Custom script:   call SetUnitPathing( disease2, false )
        Custom script:   call CreateNUnitsAtLoc( 1, 'e000', GetOwningPlayer(GetSpellAbilityUnit()), unitlocation, bj_UNIT_FACING )
        Custom script:   set disease3 = GetLastCreatedUnit()
        Custom script:   call SetUnitPathing( disease3, false )
        Custom script:   call IssuePointOrderLocBJ( disease1, "move", movepoint )
        Custom script:   set movepoint = PolarProjectionBJ( unitlocation, 256, ( AngleBetweenPoints( unitlocation, targetloc ) + 25.00 ) )
        Custom script:   call IssuePointOrderLocBJ( disease2, "move", movepoint )
        Custom script:   set movepoint = PolarProjectionBJ( unitlocation, 256, ( AngleBetweenPoints( unitlocation, targetloc ) - 25.00 ) )
        Custom script:   call IssuePointOrderLocBJ( disease3, "move", movepoint )
        Custom script:   call RemoveLocation( targetloc )
        Custom script:   call RemoveLocation( unitlocation )
        Custom script:   call RemoveLocation( movepoint )
        Wait 0.90 seconds
        Custom script:   call RemoveUnit( disease1 )
        Custom script:   call RemoveUnit( disease2 )
        Custom script:   call RemoveUnit( disease3 )
 
because im afraid just straight jass and this way is easier to debug for me, i can disable any 1 line all easy like with a right click.

and what about this

set poisonspot = GetRandomLocInRect(RectFromCenterSizeBJ(GetUnitLoc(GetSpellAbilityUnit()), udg_tempReal, udg_tempReal))

if i call the function to remove the poisonspot location will i still have a leak from the rect?
 
Grundy said:
Code:
toxic breath
    Events
        Unit - A unit Starts the effect of an ability
    Conditions
        (Ability being cast) Equal to Toxic Breath (Breath of Fire (Neutral Hostile))
    Actions
        Custom script:   local unit disease1
        Custom script:   local unit disease2
        Custom script:   local unit disease3
        Custom script:   local location targetloc = GetSpellTargetLoc()
        Custom script:   local location unitlocation = PolarProjectionBJ([B]GetUnitLoc(GetSpellAbilityUnit())[/B], 75.00, AngleBetweenPoints([B]GetUnitLoc(GetSpellAbilityUnit())[/B], targetloc))
        Custom script:   local location movepoint = PolarProjectionBJ( unitlocation, 256, AngleBetweenPoints(unitlocation, targetloc))
        Custom script:   call CreateNUnitsAtLoc( 1, 'e000', GetOwningPlayer(GetSpellAbilityUnit()), unitlocation, bj_UNIT_FACING ) 
        Custom script:   set disease1 = GetLastCreatedUnit()
        Custom script:   call SetUnitPathing( disease1, false )
        Custom script:   call CreateNUnitsAtLoc( 1, 'e000', GetOwningPlayer(GetSpellAbilityUnit()), unitlocation, bj_UNIT_FACING )
        Custom script:   set disease2 = GetLastCreatedUnit()
        Custom script:   call SetUnitPathing( disease2, false )
        Custom script:   call CreateNUnitsAtLoc( 1, 'e000', GetOwningPlayer(GetSpellAbilityUnit()), unitlocation, bj_UNIT_FACING )
        Custom script:   set disease3 = GetLastCreatedUnit()
        Custom script:   call SetUnitPathing( disease3, false )
        Custom script:   call IssuePointOrderLocBJ( disease1, "move", movepoint )
        Custom script:   set movepoint = PolarProjectionBJ( unitlocation, 256, ( AngleBetweenPoints( unitlocation, targetloc ) + 25.00 ) )
        Custom script:   call IssuePointOrderLocBJ( disease2, "move", movepoint )
        Custom script:   set movepoint = PolarProjectionBJ( unitlocation, 256, ( AngleBetweenPoints( unitlocation, targetloc ) - 25.00 ) )
        Custom script:   call IssuePointOrderLocBJ( disease3, "move", movepoint )
        Custom script:   call RemoveLocation( targetloc )
        Custom script:   call RemoveLocation( unitlocation )
        Custom script:   call RemoveLocation( movepoint )
        Wait 0.90 seconds
        Custom script:   call RemoveUnit( disease1 )
        Custom script:   call RemoveUnit( disease2 )
        Custom script:   call RemoveUnit( disease3 )

You are leaking in the polar projections where you have GetUnitLoc().
And you have to set all local handles to null at the end. (handles are everything but code, string, real, integer, boolean)

Alos I suggest that you use CreateUnitAtLoc and merge it with the disease set. Like this:
Code:
        Custom script:   set disease1 =  CreateUnitAtLoc( GetOwningPlayer(GetSpellAbilityUnit()), 'e000', , unitlocation, bj_UNIT_FACING )




Code:
set poisonspot = GetRandomLocInRect(RectFromCenterSizeBJ(GetUnitLoc(GetSpellAbilityUnit ()), udg_tempReal, udg_tempReal))

It will leak both from the rect and the GetUnitLoc()



TIPS:
You can equal easy dissable things in jass script. Just put a // before and it will be counted as a comment. This way you even can dissable parts of a line
like "set integer = integer *5 // + 3"
 
All your "Loc" lines are leaking locations.
I suggest you use X and Y's. local real x1 = GetLocationX(unit/location)
local real y1 = GetLocationY(unit/location)
call CreateUnit(GetOwningPlayer(unit), 'rawcode', x, y, -anglehere- (270 for default))

just an example.
 
does this fix the leaks

Code:
toxic breath
    Events
        Unit - A unit Starts the effect of an ability
    Conditions
        (Ability being cast) Equal to Toxic Breath (Breath of Fire (Neutral Hostile))
    Actions
        Custom script:   local location targetloc = GetSpellTargetLoc()
        Custom script:   local location casterloc = GetUnitLoc( GetSpellAbilityUnit() )
        Custom script:   local location unitlocation = PolarProjectionBJ( casterloc, 75.00, AngleBetweenPoints( casterloc, targetloc))
        Custom script:   local location movepoint
        Custom script:   local unit disease1
        Custom script:   local unit disease2
        Custom script:   local unit disease3
        Custom script:   set disease1 =  CreateUnitAtLoc( GetOwningPlayer(GetSpellAbilityUnit()), 'e000', unitlocation, bj_UNIT_FACING ) 
        Custom script:   call SetUnitPathing( disease1, false )
        Custom script:   set disease2 =  CreateUnitAtLoc( GetOwningPlayer(GetSpellAbilityUnit()), 'e000', unitlocation, bj_UNIT_FACING ) 
        Custom script:   call SetUnitPathing( disease2, false )
        Custom script:   set disease3 =  CreateUnitAtLoc( GetOwningPlayer(GetSpellAbilityUnit()), 'e000', unitlocation, bj_UNIT_FACING ) 
        Custom script:   call SetUnitPathing( disease3, false )
        Custom script:   set movepoint = PolarProjectionBJ( unitlocation, 256, AngleBetweenPoints(unitlocation, targetloc))
        Custom script:   call IssuePointOrderLocBJ( disease1, "move", movepoint )
        Custom script:   call RemoveLocation( movepoint )
        Custom script:   set movepoint = PolarProjectionBJ( unitlocation, 256, ( AngleBetweenPoints( unitlocation, targetloc ) + 25.00 ) )
        Custom script:   call IssuePointOrderLocBJ( disease2, "move", movepoint )
        Custom script:   call RemoveLocation( movepoint )
        Custom script:   set movepoint = PolarProjectionBJ( unitlocation, 256, ( AngleBetweenPoints( unitlocation, targetloc ) - 25.00 ) )
        Custom script:   call IssuePointOrderLocBJ( disease3, "move", movepoint )
        Custom script:   call RemoveLocation( movepoint )
        Custom script:   set movepoint = null
        Custom script:   call RemoveLocation( targetloc )
        Custom script:   set targetloc = null
        Custom script:   call RemoveLocation( casterloc )
        Custom script:   set casterloc = null
        Custom script:   call RemoveLocation( unitlocation )
        Custom script:   set unitlocation = null
        Wait 0.90 seconds
        Custom script:   call RemoveUnit( disease1 )
        Custom script:   set disease1 = null
        Custom script:   call RemoveUnit( disease2 )
        Custom script:   set disease2 = null
        Custom script:   call RemoveUnit( disease3 )
        Custom script:   set disease3 = null
 
i dont see any more leaks however when you say
call RemoveLocation( movepoint )
this will destroys the created object so movepoint variable becomes null so you dont need to nullify the move point.
also thats same for
call RemoveUnit( disease1 )

we nullify some unit variables such as caster or any other object that will continue in game after spell or action to create a lil more space on cache.
 
alright i guess i misunderstood phyrex1an whe he said
phyrex1an said:
And you have to set all local handles to null at the end. (handles are everything but code, string, real, integer, boolean)
or maybe i understood him right and he was wrong?
 
Actualy I have no idea ^^. I set all local handle variables to null at the end of the function. Even if object they are pointing to is destroyed. And I have seen that alot of people also do so.

But this is what I THINK:
There is a 'table' in wc3 that holds all objects pointers. If the object is removed the pointer is still there and is not recycled until any of the variables that pointed to the now removed object is nulled. So if you dont null a variable it will leak a small amount (4bytes?).
But that is what I think so it may be compleatley wrong ^^,
 
ok how about this one:

Code:
check
    Events
        Player - Player 1 (Red) types a chat message containing check as An exact match
    Conditions
    Actions
        Set tempLocation = (Position of Blademaster 0002 <gen>)
        Unit Group - Remove all units from tempGroup
        Unit Group - Pick every unit in (Units within 512.00 of tempLocation) and do (Actions)
            Loop - Actions
                Unit Group - Add (Picked unit) to tempGroup
        Custom script:   call DestroyLocation( udg_tempLocation )
        Custom script:   call DestroyGroup( GetLastCreatedGroup() )
        Unit Group - Pick every unit in tempGroup and do (Actions)
            Loop - Actions
                Game - Display to (All players) the text: (String((Unit-type of (Picked unit))))

will this fix the unit group leak? im thinking the GetLastCreatedGroup() function should return the group that was made by the Unit Group - Pick every unit in range action, and destroy that group and fix any leak.
 
Grundy said:
ok how about this one:

Code:
check
    Events
        Player - Player 1 (Red) types a chat message containing check as An exact match
    Conditions
    Actions
        Set tempLocation = (Position of Blademaster 0002 <gen>)
        Unit Group - Remove all units from tempGroup
        Unit Group - Pick every unit in (Units within 512.00 of tempLocation) and do (Actions)
            Loop - Actions
                Unit Group - Add (Picked unit) to tempGroup
        Custom script:   call DestroyLocation( udg_tempLocation )
        Custom script:   call DestroyGroup( GetLastCreatedGroup() )
        Unit Group - Pick every unit in tempGroup and do (Actions)
            Loop - Actions
                Game - Display to (All players) the text: (String((Unit-type of (Picked unit))))

will this fix the unit group leak? im thinking the GetLastCreatedGroup() function should return the group that was made by the Unit Group - Pick every unit in range action, and destroy that group and fix any leak.


GetLastCreatedGroup creates a new group ( :nuts: ) with the same units that was created with the CreateNUnits gui thing.

2 ways to do what u want:
Code:
check
    Events
        Player - Player 1 (Red) types a chat message containing check as An exact match
    Conditions
    Actions
        Set tempLocation = (Position of Blademaster 0002 <gen>)
        Set tempGroup = (Units within 512.00 of tempLocation) 
        Custom script:   call DestroyLocation( udg_tempLocation )
        Unit Group - Pick every unit in tempGroup and do (Actions)
            Loop - Actions
                Game - Display to (All players) the text: (String((Unit-type of (Picked unit))))
        Custom script:   call DestroyGroup( udg_tempGroup )

or

Code:
check
    Events
        Player - Player 1 (Red) types a chat message containing check as An exact match
    Conditions
    Actions
        Set tempLocation = (Position of Blademaster 0002 <gen>)
        Custom Script: set bj_wantDestroyGroup = true
        Unit Group - Pick every unit in (Units within 512.00 of tempLocation) and do (Actions)
            Loop - Actions
                Game - Display to (All players) the text: (String((Unit-type of (Picked unit))))
        Custom script:   call DestroyLocation( udg_tempLocation )
 
oooo nice i saw that part about wantDestroy but i thought it was pointless because it sets it to false. but now that i look at it again, it sets the local to whatever it starts at and then sets the global back to false and keeps the local the same. now i get it.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • The Helper The Helper:
    got it
  • The Helper The Helper:
    Happy Thursday!
  • The Helper The Helper:
    Check out the new Featured Content feature we apparently got with the forum software upgrade! https://www.thehelper.net/featured/
  • The Helper The Helper:
    Also on the bottom right side bar we now have a Trending Content Box!
    +1
  • The Helper The Helper:
    Not on the Headline News page just on the Forums page can we get that Featured and Trending on the home page?
  • Ghan Ghan:
    Since the home page is technically a forum, it now shows on all forum views. Still in the sidebar.
    +1
  • The Helper The Helper:
    Happy Friday! Hope everyone has a fantastic day and an even better weekend!
  • The Helper The Helper:
    Happy Sunday!
  • The Helper The Helper:
    I lovc that I can post webp and X links now! :)
  • The Helper The Helper:
    Happy Thursday!
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    we were down for a minute - think a log file or something got too big
    +1
  • Ghan Ghan:
    The alerts say it was down for a while unfortunately.
  • Ghan Ghan:
    Didn't know what was going on while I was at work.
  • Ghan Ghan:
    Disk filled up with logs. Fixed now.
    +1
  • The Helper The Helper:
    not a problem at all thanks for getting us back up
  • The Helper The Helper:
    I think the bots are finding a way to get through the anubis
  • The Helper The Helper:
    Happy Wednesday Everyone! Hope everyone has a Fantastic Day!
    +1
  • The Helper The Helper:
    Yeah, stats are showing big bot influx like 12k page views.
  • Wizard Wizard:
    :wave:
    +1
  • Ghan Ghan:
    TH changed his avatar again. 6 more weeks of summer.
    +3
  • Wizard Wizard:
    lol
    +1
  • The Helper The Helper:
    Guys just a heads up I am going to be shutting the site down soon. I am just waiting on the NUON people to decide whether they want to transfer forum data and keep the discord. My email is [email protected] for anyone that wants to keep in touch and I have a facebook too. I will make an official post later. Love you guys and will miss everyone!
    +1
  • V-SNES V-SNES:
    Sent a pm @The Helper

The Helper Discord

Members online

No members online now.

Affiliates

Hive Workshop NUON Dome World Editor Tutorials
Back
Top