Welcome Guest [Log In] [Register]
Welcome to Chaos Realm!!!


You're currently viewing our forum as a guest. This means you are limited to certain areas of the board and there are some features you can't use. If you join our community, you'll be able to access member-only sections, and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.


Join our community!


If you're already a member please log in to your account to access all of our features:

Username:   Password:
Multiquote Multiquote
Add Reply
[BASICS] Lesson #3: Memory Leak Detection; What are "Leaks"? Why should I remove them? How to detect them?
Topic Started: Jan 27 2015, 12:03 AM (2,749 Views)
Banditger
Member Avatar
Digimon Kaiser
[ *  *  *  *  *  *  *  *  *  * ]
In this lesson I will explain what Memory Leaks are, how they are caused and why you should remove them.

This will be some programming stuff now. cool beans

Everytime a variable is created, like a group, a point, a unit, a region or whatever can be created, a part of the memory is used for this. This part of the memory can not be used by other stuffs you do.

Now if a trigger is called often without freeing that memory, you lock a lot of memory.
If this happens often, your memory will be full and so Warcraft will work slower, causing laggs.

Summarized: If leaks are not removed, Warcraft will lagg. em_whatthe


But what do I have to remove? Simple:
Special Effects
Groups
Points
Units
Regions
Forces
Lightning Effects
Floating Text
Countdown Timers

and more, but those are the ones often used.

[gui] Events
Conditions
Actions
Unit Group - Pick every unit in (Units in (Playable map area)) and do (Actions)
Loop - Actions
Unit - Kill (Picked unit)[/gui]

This trigger contains a leak which is (Units in (Playable map area)). This is a group (if you click it, it will says group, also you can add a group variable there instead).

To fix this, do something like this:

[gui] Events
Conditions
Actions
Set Temp_Group = (Units in (Playable map area))
Unit Group - Pick every unit in Temp_Group and do (Actions)
Loop - Actions
Unit - Kill (Picked unit)
Custom script: call DestroyGroup (udg_Temp_Group)[/gui]

This Trigger sets the Unit Group into a new variable and after that destroyes the variable.

[gui]Custom script: call DestroyGroup (udg_Temp_Group)[/gui]

This Action is actually Jass! call DestroyGroup(udg_Temp_Group) destroyes the groupvariable "Temp_Group"


Heres some larger explanation:

call DestroyGroup(parameter) is a function which needs a text as parameter. the parameter we have is "udg_Temp_Group". All variables you create using the GUI (We take a look back at Lesson 2 - Variable Creation) will be called "udg_variablename".

So to destroy the group "test_group" you have to call

[gui]Custom script: call DestroyGroup(udg_test_group)[/gui]

Now this function only frees groups. But there are more functions.

[gui]Custom script: call RemoveLocation (udg_Temp_Point)[/gui]
this removes a point. It is best to remove a location only when it is no longer used. You can use the variables many times before you remove it.

To remove a Special Effect, you do this:
[gui] Events
Conditions
Actions
Set Temp_Point = (Center of (Playable map area))
Special Effect - Create a special effect at Temp_Point using Abilities\Spells\Human\ThunderClap\ThunderClapCaster.mdl
Special Effect - Destroy (Last created special effect)
Special Effect - Create a special effect at Temp_Point using Abilities\Spells\Human\ThunderClap\ThunderClapCaster.mdl
Special Effect - Destroy (Last created special effect)
Custom script: call RemoveLocation (udg_Temp_Point)[/gui]

Here you destroy the special effect (using GUI, yay) and then Remove the Location it uses. Locations are the most cause of leaks.

If you create a unit, you also have to remove it later on.
[gui] Events
Conditions
Actions
Set Temp_Point = (Center of (Playable map area))
Unit - Create 1 Dummy Caster for Player 1 (Red) at Temp_Point facing Default building facing degrees
Custom script: call RemoveLocation (udg_Temp_Point)
Unit - Add a 2.00 second Generic expiration timer to (Last created unit)[/gui]

This works.

There is also

[gui]
Custom script: call DestroyForce( udg_Your_Variable ) //Player Group
Custom script: call RemoveRect(udg_Your_Variable) //Region
Custom script: call DestroyLightning( udg_Your_Variable ) //Lightning Effect
Custom script: call DestroyTextTag( udg_Your_Variable ) //Floating Text
Custom script: call DestroyTimer( udg_Your_Variable ) //Countdown Timer
Custom script: call DestroyTrigger( GetTriggeringTrigger() )
[/gui]

Its always best to use Jass because its faster and all you need. I will explain that in another lesson.


If I forgot something here, please tell me and I will add it. Memory management is really important if your map is played long or your spell is casted often:

Homework:
-Try some of the above, try to call every custom script you see above within a trigger you make.
-Remove leaks in all your triggers you did so far.
Edited by Banditger, Jan 27 2015, 12:06 AM.
My Facebook

Spells/Systems
My Spells
Cero
Combo-Attack
Naruto Spells
Holy Ring
Death Bomb
Shinra Tensei
Sphere of Lightning
Starburst Stream
My Systems
Arrow Movement System
Knockback System
Change Texture
Puppet System
Rips
Digimon Rips
Offline Profile Quote Post
 
RiskYourLife
Member Avatar
Crypt Lord Level 3
[ *  *  * ]
Quote:
 
and more, but those are the ones often used.
[gui]
Events
Conditions
Actions
Unit Group - Pick every unit in (Units in (Playable map area)) and do (Actions)
Loop - Actions
Unit - Kill (Picked unit)
[/gui]

This trigger contains a leak which is (Units in (Playable map area)). This is a group (if you click it, it will says group, also you can add a group variable there instead).

To fix this, do something like this:

[gui] Events
Conditions
Actions
Set Temp_Group = (Units in (Playable map area))
Unit Group - Pick every unit in Temp_Group and do (Actions)
Loop - Actions
Unit - Kill (Picked unit)
Custom script: call DestroyGroup (udg_Temp_Group)
[/gui]


Unit group also can be remove by doing this
[gui] Events
Conditions
Actions
Custom script: set bj_wantDestroyGroup = true
Unit Group - Pick every unit in (Units in (Playable map area)) and do (Actions)
Loop - Actions
Unit - Kill (Picked unit)
[/gui]

The (Units in (Playable map area)) group will automatically get removed after the loop ends


Also, I noticed lately some coder remove their leaks like this
[gui] Events
Conditions
Actions
Set Temp_point[1] = (Position of (Triggering unit))
For each (Integer A) from 1 to 10, do (Actions)
Loop - Actions
Set Temp_point[2] = (Temp_point[1] offset by 256.00 towards ((Real((Integer A))) + 36.00) degrees)
Unit - Create 1 Footman for Player 1 (Red) at Temp_point[3] facing Default building facing degrees
Custom script: set bj_wantDestroyGroup = true
Unit Group - Pick every unit in (Units within 512.00 of Temp_point[1]) and do (Actions)
Loop - Actions
Set Temp_point[3] = (Position of (Picked unit))
Unit - Create 1 Footman for Player 1 (Red) at Temp_point[3] facing Default building facing degrees
Custom script: call RemoveLocation(udg_Temp_point[1])
Custom script: call RemoveLocation(udg_Temp_point[2])
Custom script: call RemoveLocation(udg_Temp_point[3])
[/gui]

Actually, that way is wrong. The correct way to remove the leaks is like this
[gui] Events
Conditions
Actions
Set Temp_point[1] = (Position of (Triggering unit))
For each (Integer A) from 1 to 10, do (Actions)
Loop - Actions
Set Temp_point[2] = (Temp_point[1] offset by 256.00 towards ((Real((Integer A))) + 36.00) degrees)
Unit - Create 1 Footman for Player 1 (Red) at Temp_point[3] facing Default building facing degrees
Custom script: call RemoveLocation(udg_Temp_point[2])
Custom script: set bj_wantDestroyGroup = true
Unit Group - Pick every unit in (Units within 512.00 of Temp_point[1]) and do (Actions)
Loop - Actions
Set Temp_point[3] = (Position of (Picked unit))
Unit - Create 1 Footman for Player 1 (Red) at Temp_point[3] facing Default building facing degrees
Custom script: call RemoveLocation(udg_Temp_point[3])
Custom script: call RemoveLocation(udg_Temp_point[1])
[/gui]

These code above is loop which mean it will do same thing until it meet certain condition. So, location must be removed inside the loop.





Quote:
 
If you create a unit, you also have to remove it later on.
[gui] Events
Conditions
Actions
Set Temp_Point = (Center of (Playable map area))
Unit - Create 1 Dummy Caster for Player 1 (Red) at Temp_Point facing Default building facing degrees
Custom script: call RemoveLocation (udg_Temp_Point)
Unit - Add a 2.00 second Generic expiration timer to (Last created unit)
[/gui]


This works.


Correct me if Im wrong. The code above will kill Dummy caster after 2.00 second passed and it will create a corpse of the dummy. Thats mean the code does not remove the unit/leak, it just kill it. So, to remove the leak, create a new trigger like this one
[gui]DummyRemove
Events
Unit - A unit Dies
Conditions
(Unit-type of (Triggering unit)) Equal to Dummy Caster
Actions
Unit - Remove (Triggering unit) from the game
-------- actions --------
[/gui]
Edited by RiskYourLife, Mar 27 2016, 03:20 AM.
Offline Profile Quote Post
 
Banditger
Member Avatar
Digimon Kaiser
[ *  *  *  *  *  *  *  *  *  * ]
A corpse will get removed after some time automatically, so no leak here. If this would not happen, a leak would be created if a unit kills another, which happens quite often.

If a lot of corpses are created which causes laggs, your trigger can be used. But that sounds like a workaround rather than a real fix of the problem, not to create a lot of corpses in the first place.
Edited by Banditger, Jan 9 2017, 06:00 PM.
My Facebook

Spells/Systems
My Spells
Cero
Combo-Attack
Naruto Spells
Holy Ring
Death Bomb
Shinra Tensei
Sphere of Lightning
Starburst Stream
My Systems
Arrow Movement System
Knockback System
Change Texture
Puppet System
Rips
Digimon Rips
Offline Profile Quote Post
 
1 user reading this topic (1 Guest and 0 Anonymous)
« Previous Topic · Triggering Classes · Next Topic »
Add Reply

War3 Modding

Blizzard Modding

Other Games

Community

MARKET
Models & Skins
Spells
Ongoing Contests
Hosted Projects
World of Warcraft
Starcraft 2
Diablo III
Heroes of the Storm
Dota 2
League of Legends
Members
Awards
Introductions
Contact

Copyright © 2011-2015 Chaos Realm. A project initiated by Bogdan Radu.