• 🏆 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!

[Solved] Is this attack type switch system creating memory leaks?

Status
Not open for further replies.
Level 5
Joined
Sep 25, 2021
Messages
28
Context

Looking at my functional system that changes weapon types in a "Unit", I wonder if this is creating a memory leak.

The system uses the following triggers:


  • DoomhammerAbility
    • Events
      • Unit - A unit owned by Player 1 (Red) Begins casting an ability
    • Conditions
      • (Ability being cast) Equal to Metamorphosis (Normal to Magic)
    • Actions
      • Player - Disable Metamorphosis (Normal to Magic) for Player 1 (Red)
      • Player - Enable Bear Form (Magic to Siege) for Player 1 (Red)
  • DoomhammerAbility02
    • Events
      • Unit - A unit owned by Player 1 (Red) Begins casting an ability
    • Conditions
      • (Ability being cast) Equal to Bear Form (Magic to Siege)
    • Actions
      • Player - Disable Bear Form (Magic to Siege) for Player 1 (Red)
      • Player - Enable Storm Crow Form (Siege to Normal) for Player 1 (Red)
  • DoomhammerAbility03
    • Events
      • Unit - A unit owned by Player 1 (Red) Begins casting an ability
    • Conditions
      • (Ability being cast) Equal to Storm Crow Form (Siege to Normal)
    • Actions
      • Player - Disable Storm Crow Form (Siege to Normal) for Player 1 (Red)
      • Player - Enable Metamorphosis (Normal to Magic) for Player 1 (Red)


How it Works:

The unit in question exists already in the map and has the three abilities represented in each condition (Metamorphosis (Normal to Magic); Bear Form (Magic to Siege); Storm Crow Form (Siege to Normal)).

Now, like the name says, each ability is a different morph ability that uses alternately the "Data - Normal Form Unit" and "Data - Alternate Form Unit" like this:

Metamorphosis (Normal to Magic): Data - Normal Form Unit: Blackrock Smith (Normal); Data - Alternate Form Unit: Blackrock Smith (Magic);
Bear Form (Magic to Siege): Data - Normal Form Unit: Blackrock Smith (Magic); Data - Alternate Form Unit: Blackrock Smith (Siege);
Storm Crow Form (Siege to Normal): Data - Normal Form Unit: Blackrock Smith (Siege); Data - Alternate Form Unit: Blackrock Smith (Normal);




How it appears:

The system seems to work as intended: Whenever the Unit (Blackrock Smith (Normal)) uses Metamorphosis it will turn into a similar unit (Blackrock Smith (Magic)) with the previous unit stats (exp, str, int, agi, ...). Then Metamorphosis gets disabled and only Bear Form can be used by Blackrock Smith (Magic). By using Bear Form, this unit becomes Blackrock Smith (Siege) with only Storm Crow Form ability enabled.




What it might be doing:

Now here's the part where I'm guessing it might create memory leaks:

When Blackrock Smith (Siege) uses Storm Crow Form to become Blackrock Smith (Normal), is it creating a new unit (a Blackrock Smith (Normal)01), maintaining the initial unit in the data along with this new one? Is it deleting it? Is it reversing exactly to the data referencing to that initial unit?

This also because I'm never using turn off on these abilities, only Turn On and so on.




If it is creating memory leaks, please reply to this thread so I can disable this on the map I'm currently working on. If there are better ways to do it (change three times the attack type value from a Hero unit), please reply as well.

Otherwise, how can I detect if it is creating leaks?

I know that at least it is possible to change two times the attack type value from a Hero unit with Attack 1 and Attack 2 switches.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,583
There's no memory leaks here. The unit's Handle id doesn't change when morphing so you don't have to worry about something like that.

I believe these are the only 2 cases where you have to clean up Unit leaks in GUI:

Nulling local unit variables:
  • Custom script: local unit u = GetTriggerUnit()
  • Custom script: set u = null
Clearing unit handles from a hashtable:
  • Hashtable - Save Key(Something) as 0 of Key(Some unit) in Hashtable
  • Hashtable - Clear Key(Some unit) in Hashtable

The main culprits for leaks in GUI are Points, Unit Groups, Player Groups, and Special Effects. You should rarely be dealing with any leaks besides these.

When working in Jass you'll be using local variables far more often which need to be nulled.
 
Level 5
Joined
Sep 25, 2021
Messages
28
There's no memory leaks here. The unit's Handle id doesn't change when morphing so you don't have to worry about something like that.

I believe these are the only 2 cases where you have to clean up Unit leaks in GUI:

Nulling local unit variables:
  • Custom script: local unit u = GetTriggerUnit()
  • Custom script: set u = null
Clearing unit handles from a hashtable:
  • Hashtable - Save Key(Something) as 0 of Key(Some unit) in Hashtable
  • Hashtable - Clear Key(Some unit) in Hashtable

The main culprits for leaks in GUI are Points, Unit Groups, Player Groups, and Special Effects. You should rarely be dealing with any leaks besides these.

When working in Jass you'll be using local variables far more often which need to be nulled.
Thank you! I'll try to remember those cases should I use them.

I knew that I should be aware with Unit Groups and Points, but this case was making me think if it could also be a problem.

Best regards.
 
Status
Not open for further replies.
Top