quick memory leak question

afisakov

You can change this now in User CP.
Reaction score
37
I know most points like GetUnitLoc tend to leak, but does point offset as well?
for example
Trigger:
  • testtrigger
    • Actions
      • Set TempPoint = (Position of (Triggering unit))
      • Unit - Create 1 Footman (2) for Player 1 (Red) at (TempPoint offset by (0.00, 100.00)) facing Default building facing degrees
      • Unit - Create 1 Footman (2) for Player 1 (Red) at (TempPoint offset by (0.00, -100.00)) facing Default building facing degrees
      • Custom script: call RemoveLocation(udg_TempPoint)


Also, I believe GetRectCenter(region_001) does leak but wanted to confirm.
 

Accname

2D-Graphics enthusiast
Reaction score
1,463
I am not 100% sure about the center of a rect, but I think it does. If you want to be certain you can look at the Jass implementation of these methods. The offset definitely leaks though.

The reason I believe the center of rect leaks is that if you remove the location you can "get" it again by calling GetRectCenter another time. This implies that a new Point-Object is generated on each call. Take UnitGroups as an example. UnitGroups leak if you create them with functions like "get all units inside rect" or something like that. But if you simply add units to a group, remove the units, etc it does not leak. It always uses the same group. If you were to destroy a group and then try to add units to it it wouldnt work. There would be no group to have units added to.
 

afisakov

You can change this now in User CP.
Reaction score
37

Accname

2D-Graphics enthusiast
Reaction score
1,463
blizzard.j defines it as
JASS:
function GetRectCenter takes rect whichRect returns location
    return Location(GetRectCenterX(whichRect), GetRectCenterY(whichRect))
endfunction

does the fact it uses return Location mean it creates a location=point and therefore leaks
Yes. Where it says "Location(...)" it creates a new Location-Object and therefore leaks memory. This object needs to be removed/destroyed or else it will continue to exist within your RAM.
 

afisakov

You can change this now in User CP.
Reaction score
37
Another question, if a trigger has no waits in it, am I safe from other triggers overwriting the variables, or could other triggers still jump in midway?

for example
trigger 1:
unit starts effect of ability
ability=blaze
set temppoint=spelltargetlocation
set tempgroup=unitsinrangeoflocationmatching...
call forgroup(tempgroup, damage function)
call DestroyGroup(tempgroup)
call Removelocation(temppoint)

trigger 2:
a unit dies
dying unit=spider
set temppoint=getunitlocation(triggerunit)
createitemloc(temppoint)
call RemoveLocation(temppoint)

yes I know these are in pseudocode, did not look up exact names for example.
The question is, if trigger 1 kills several units, trigger 2 activate each time and "steal" the temppoint before it can be removed at the end, causing a leak? or will it wait to process triggers 2 after trigger 1 completes?
 

Accname

2D-Graphics enthusiast
Reaction score
1,463
That is something which should be fairly easy for you to test, isnt it?

But as far as I know only a wait can cause one trigger to yield control to another. (and of course calling the other directly!)
 

afisakov

You can change this now in User CP.
Reaction score
37
In case anyone wanted to know, I did test this with another trigger and proved it can lose control of variables without a wait.

the first trigger sets global variable fint2 based on hero str and other data, deals damage, and then displays a texttag of how much damage dealt, all without waits.
The second sets fint2 based on unittype of dying unit and pays bonus gold.

Baseed on play-testing
If the target survives the dmg display matches dmg done in first trigger, but if the target dies it displays the bonus gold instead. Triggers below, removed some unneeded parts for ease of viewing.

JASS:
function Trig_FSkillDK_Conditions takes nothing returns boolean
return (GetSpellAbilityId()=='A0YZ')
endfunction
function Trig_FSkillDK_Actions takes nothing returns nothing
set fint2=GetHeroStr(GetTriggerUnit(),true)*(GetUnitAbilityLevelSwapped('A0YZ',GetTriggerUnit())+1)+udg_SoulInt*20
call UnitDamageTargetBJ(GetTriggerUnit(),GetSpellTargetUnit(),fint2,ATTACK_TYPE_NORMAL,DAMAGE_TYPE_UNIVERSAL)
set udg_Lock=GetUnitLoc(GetSpellTargetUnit())
call AddSpecialEffectLocBJ(udg_Lock,"Abilities\\Spells\\Undead\\RaiseSkeletonWarrior\\RaiseSkeleton.mdl")
call DestroyEffectBJ(GetLastCreatedEffectBJ())
call CreateTextunit_sec_speed(I2S(fint2),GetSpellTargetUnit(),3,30,10.00,13.00,20.00,20.00,90.00,15.00)
call RemoveLocation(udg_Lock)
...
endfunction


JASS:
event: a unit dies

function Trig_Money_creeps_Actions takes nothing returns nothing
local integer uid=GetUnitTypeId(GetTriggerUnit())
local texttag tag1
local unit u=GEtKillingUnit()
if (uid=='uske') then
set fint4=2
elseif (uid=='ucry')or(uid=='nnwa') then
set fint4=3
elseif (uid=='nzom')or(uid=='ugho')or(uid=='nits') then
set fint4=4
endif
...
call SetPlayerState(GetOwningPlayer(u),PLAYER_STATE_RESOURCE_GOLD,GetPlayerState(GetOwningPlayer(u),PLAYER_STATE_RESOURCE_GOLD) + fint2+rcount(u) )
...endfunction
 

afisakov

You can change this now in User CP.
Reaction score
37
But as far as I know only a wait can cause one trigger to yield control to another.
In my test, trigger 2 stole control of "fint2" before trigger 1 was done with it. Specifically after dealing damage but before displaying the texttag, without a wait or a direct call.

This is also relevant for cleaning up leaks in general because it shows you cannot use the same temppoint for everything. If you use it for "a unit dies" events to drop items this can cause it to overwrite the one still open in your damage triggers (used to select tempgroup in area) and cause that to leak. Even if neither trigger contains waits.
 

jonas

You can change this now in User CP.
Reaction score
67
is it intentional that you use fint4 in the second trigger?

Also, control is the position in the code, ownership is who has access to the variables.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top