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,462
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,462
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,462
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
66
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.
  • The Helper The Helper:
    So what it really is me trying to implement some kind of better site navigation not change the whole theme of the site
  • Varine Varine:
    How can you tell the difference between real traffic and indexing or AI generation bots?
  • The Helper The Helper:
    The bots will show up as users online in the forum software but they do not show up in my stats tracking. I am sure there are bots in the stats but the way alot of the bots treat the site do not show up on the stats
  • Varine Varine:
    I want to build a filtration system for my 3d printer, and that shit is so much more complicated than I thought it would be
  • Varine Varine:
    Apparently ABS emits styrene particulates which can be like .2 micrometers, which idk if the VOC detectors I have can even catch that
  • Varine Varine:
    Anyway I need to get some of those sensors and two air pressure sensors installed before an after the filters, which I need to figure out how to calculate the necessary pressure for and I have yet to find anything that tells me how to actually do that, just the cfm ratings
  • Varine Varine:
    And then I have to set up an arduino board to read those sensors, which I also don't know very much about but I have a whole bunch of crash course things for that
  • Varine Varine:
    These sensors are also a lot more than I thought they would be. Like 5 to 10 each, idk why but I assumed they would be like 2 dollars
  • Varine Varine:
    Another issue I'm learning is that a lot of the air quality sensors don't work at very high ambient temperatures. I'm planning on heating this enclosure to like 60C or so, and that's the upper limit of their functionality
  • Varine Varine:
    Although I don't know if I need to actually actively heat it or just let the plate and hotend bring the ambient temp to whatever it will, but even then I need to figure out an exfiltration for hot air. I think I kind of know what to do but it's still fucking confusing
  • The Helper The Helper:
    Maybe you could find some of that information from AC tech - like how they detect freon and such
  • Varine Varine:
    That's mostly what I've been looking at
  • Varine Varine:
    I don't think I'm dealing with quite the same pressures though, at the very least its a significantly smaller system. For the time being I'm just going to put together a quick scrubby box though and hope it works good enough to not make my house toxic
  • Varine Varine:
    I mean I don't use this enough to pose any significant danger I don't think, but I would still rather not be throwing styrene all over the air
  • The Helper The Helper:
    New dessert added to recipes Southern Pecan Praline Cake https://www.thehelper.net/threads/recipe-southern-pecan-praline-cake.193555/
  • The Helper The Helper:
    Another bot invasion 493 members online most of them bots that do not show up on stats
  • Varine Varine:
    I'm looking at a solid 378 guests, but 3 members. Of which two are me and VSNES. The third is unlisted, which makes me think its a ghost.
    +1
  • The Helper The Helper:
    Some members choose invisibility mode
    +1
  • The Helper The Helper:
    I bitch about Xenforo sometimes but it really is full featured you just have to really know what you are doing to get the most out of it.
  • The Helper The Helper:
    It is just not easy to fix styles and customize but it definitely can be done
  • The Helper The Helper:
    I do know this - xenforo dropped the ball by not keeping the vbulletin reputation comments as a feature. The loss of the Reputation comments data when we switched to Xenforo really was the death knell for the site when it came to all the users that left. I know I missed it so much and I got way less interested in the site when that feature was gone and I run the site.
  • Blackveiled Blackveiled:
    People love rep, lol
    +1
  • The Helper The Helper:
    The recipe today is Sloppy Joe Casserole - one of my faves LOL https://www.thehelper.net/threads/sloppy-joe-casserole-with-manwich.193585/

      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