• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] How do I remove memory leaks from this unit spawn trigger?

Status
Not open for further replies.
Level 1
Joined
Oct 30, 2007
Messages
2
Hiya!

I just started making warcraft III maps a month ago.

Right now I'm trying to learn about memory leaks and how to get rid of them.

Here's some code that I'm trying to remove leaks from, but I'm not entirely sure how to do it.

Thanks in Advanced

  • General Spawner 1
    • Events
      • Time - Every 38.00 seconds of game time
    • Conditions
      • (Number of units in (Units owned by Player 10 (Light Blue))) Less than or equal to MaxPlayer10Units
      • (Grigori's Portal 0017 <gen> is alive) Equal to True
    • Actions
      • Set Temp_Point = (Center of 1 <gen>)
      • Set Temp_PointTemple = (Center of Temple <gen>)
      • Unit - Create rateMelee[1] uMeleeSpawner[iLevelsSide1[1]] for Player 10 (Light Blue) at Temp_Point facing Default building facing degrees
      • Unit Group - Order (Last created unit group) to Attack-Move To Temp_PointTemple
      • Custom script: call RemoveLocation (udg_Temp_Point)
      • Custom script: call RemoveLocation (udg_Temp_PointTemple)
      • Set Temp_Point = (Center of 1 <gen>)
      • Set Temp_PointTemple = (Center of Temple <gen>)
      • Unit - Create rateRanged[1] uRangedSpawner[iLevelsSide1[2]] for Player 10 (Light Blue) at Temp_Point facing Default building facing degrees
      • Unit Group - Order (Last created unit group) to Attack-Move To Temp_PointTemple
      • Custom script: call RemoveLocation (udg_Temp_Point)
      • Custom script: call RemoveLocation (udg_Temp_PointTemple)
      • Set Temp_Point = (Center of 1 <gen>)
      • Set Temp_PointTemple = (Center of Temple <gen>)
      • Unit - Create rateAir[1] uAirSpawner[iLevelsSide1[3]] for Player 10 (Light Blue) at Temp_Point facing Default building facing degrees
      • Unit Group - Order (Last created unit group) to Attack-Move To Temp_PointTemple
      • Custom script: call RemoveLocation (udg_Temp_Point)
      • Custom script: call RemoveLocation (udg_Temp_PointTemple)
      • Set Temp_Point = (Center of 1 <gen>)
      • Set Temp_PointTemple = (Center of Temple <gen>)
      • Unit - Create rateInvisible[1] uInvisibleSpawner[iLevelsSide1[4]] for Player 10 (Light Blue) at Temp_Point facing Default building facing degrees
      • Unit Group - Order (Last created unit group) to Attack-Move To Temp_PointTemple
      • Custom script: call RemoveLocation (udg_Temp_Point)
      • Custom script: call RemoveLocation (udg_Temp_PointTemple)
      • Set Temp_Point = (Center of 1 <gen>)
      • Set Temp_PointTemple = (Center of Temple <gen>)
      • Unit - Create rateMagic[1] uMagicSpawner[iLevelsSide1[5]] for Player 10 (Light Blue) at Temp_Point facing Default building facing degrees
      • Unit Group - Order (Last created unit group) to Attack-Move To Temp_PointTemple
      • Custom script: call RemoveLocation (udg_Temp_Point)
      • Custom script: call RemoveLocation (udg_Temp_PointTemple)
      • Set Temp_Point = (Center of 1 <gen>)
      • Set Temp_PointTemple = (Center of Temple <gen>)
      • Unit - Create rateHero[1] uHeroSpawner[iLevelsSide1[6]] for Player 10 (Light Blue) at Temp_Point facing Default building facing degrees
      • Unit Group - Order (Last created unit group) to Attack-Move To Temp_PointTemple
      • Custom script: call RemoveLocation (udg_Temp_Point)
      • Custom script: call RemoveLocation (udg_Temp_PointTemple)
 
Last edited by a moderator:
Level 11
Joined
Jun 13, 2007
Messages
570
Your setting the points (locations) to a variable then properly removing them. So thats good, no leaks there

However, you are calling Unit Groups (groups) and never destroying them. It's the same thing as a location, you need to set them to variable then destroy it afterwards. But more important, in your function you never even create a unit group, but you call for the "Last Created Unit Group", unless I overlooked something
 
Level 1
Joined
Oct 30, 2007
Messages
2
So then, I'm cleaning up leaks properly?
What I'm asking is; Is my approach correct or should I also be nulling the variables each time I use them?
Also, when I destroy the point, am I supposed to do it after every use like I did above or should I only bother to do it once per entire trigger?

And finally, as for the unit groups I read a tutorial that said,
Same lies with Unit Groups, all the actions in that GUI window, except the "Last Created Unit Group" one, will leak the unit-group they create.
For that reason I was under the impression that as long as I'm using "Last Created Unit Group", I'm not actually leaking and therefore don't need to add a DestroyGroup line of code.
Is that assumption incorrect?

Thanks again. :)
 
Level 11
Joined
Jun 13, 2007
Messages
570
you dont need to null the variable each time because changing the pointer variable (which is your location) doesn't cause any leaks, these variables are just handles. If anything, at the end of your function you can null out your variable.

Using last created unit group doesn't create a new group to leak, but you still need a group in the first place to reference. There is no unit group created at all in your trigger, therefor there is no last created group to use
 
Status
Not open for further replies.
Top