[Solved] Does a Variable Leak?

Discussion in 'Triggers & Scripts' started by Veronnis, Aug 5, 2019.

1. Veronnis

Joined:
Jul 19, 2010
Messages:
134
Resources:
6
Models:
2
Icons:
1
Maps:
3
Resources:
6
Thanks for stopping by, among the leak tutorials I've read I never gained a firm understanding of whether: 1. Recycled MUI variables leak, 2. If even a normal variable leaks.

Main Example: (Would a trigger like this leak, if so what would fix it?)

• Start
• Events
• Something Happens
• Conditions
• Actions
• Set Total_Indexes = (Total_Indexes + 1)
• Set PointA[Total_Indexes] = (Point(200.00, 200.00))
• Set PointB[Total_Indexes] = (Center of (Playable map area))
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• Total_Indexes Equal to 1
• Then - Actions
• Trigger - Turn on Loop <gen>
• Else - Actions

The Loop Function:
• Loop
• Events
• Time - Every 5.00 seconds of game time
• Conditions
• Actions
• For each (Integer Loop_Count) from 1 to Total_Indexes, do (Actions)
• Loop - Actions
• Set Angle2Measure[Loop_Count] = (Angle from PointA[Loop_Count] to PointB[Loop_Count])
• Special Effect - Create a special effect at PointA[Loop_Count] using Abilities\Spells\Human\ThunderClap\ThunderClapCaster.mdl
• Special Effect - Destroy (Last created special effect)
• -------- Clean up --------
• Set PointA[Loop_Count] = PointA[Total_Indexes]
• Set PointB[Loop_Count] = PointB[Total_Indexes]
• Set Angle2Measure[Loop_Count] = Angle2Measure[Total_Indexes]
• Set Total_Indexes = (Total_Indexes - 1)
• Set Loop_Count = (Loop_Count - 1)
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• Total_Indexes Equal to 0
• Then - Actions
• Trigger - Turn off (This trigger)
• Else - Actions

2. Pyrogasm

Joined:
Feb 27, 2007
Messages:
2,793
Resources:
1
Spells:
1
Resources:
1
The variable does not leak. The point object you allocate and never remove is what 'leaks' (because it eats memory and can never be removed once you overwrite the reference to it). You need to RemoveLocation on the 2 points before you assign them = the last index's points.

3. Veronnis

Joined:
Jul 19, 2010
Messages:
134
Resources:
6
Models:
2
Icons:
1
Maps:
3
Resources:
6
@Pyrogasm I think I understand. Thanks again for your consistent help. If you have any interest in a reward pm me a restaurant, time zone, order and pickup name and you can have lunch / dinner on me

Spell Reviewer

Joined:
Jan 18, 2005
Messages:
25,475
Resources:
3
Maps:
1
Spells:
2
Resources:
3
Variables cannot leak by their very definition of being compile time declared global or local variables. What can leak is objects the variables refer to. In the case of JASS2 there is the nasty local declared local agent variable reference counter leak on return bug. LUA has no such bug.

Joined:
Jul 19, 2010
Messages:
134
Resources:
6
Models:
2
Icons:
1
Maps:
3
Resources:
6
Thanks Doc!