HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Does this leak?

09-20-2006, 08:02 PM#1
DurotarLord
Heres the trigger
Trigger:
Slash
Collapse Events
Unit - A unit Starts the effect of an ability
Collapse Conditions
(Ability being cast) Equal to Slash
Collapse Actions
Custom script: local unit udg_tempunit
Set tempunit = (Casting unit)
Set temppoint = (Target point of ability being cast)
Special Effect - Create a special effect at (Position of (Casting unit)) using Abilities\Spells\Orc\MirrorImage\MirrorImageCaster.mdl
Special Effect - Destroy (Last created special effect)
Collapse For each (Integer A) from 1 to (Integer((Distance between (Position of (Casting unit)) and (Target point of ability being cast)))), do (Actions)
Collapse Loop - Actions
Set tempregion = (Region centered at ((Position of (Casting unit)) offset by (Real((Integer A))) towards (Facing of (Casting unit)) degrees) with size (150.00, 150.00))
Set tempgroup = (Units in tempregion matching ((Owner of (Matching unit)) Not equal to (Random player from (All allies of (Owner of (Casting unit))))))
Unit Group - Add all units of tempgroup to tempgroup2
Custom script: call SetUnitAnimationByIndex(udg_tempunit, 6)
Collapse For each (Integer B) from 1 to (Number of units in tempgroup2), do (Actions)
Collapse Loop - Actions
Set tempunit = (Random unit from tempgroup2)
Unit - Cause (Casting unit) to damage tempunit, dealing ((16.00 + (4.00 x (Real((Level of Slash for (Casting unit)))))) + (0.10 x (Real((Agility of (Casting unit) (Include bonuses)))))) damage of attack type Spells and damage type Normal
Special Effect - Create a special effect at (Position of tempunit) using Objects\Spawnmodels\Human\HumanBlood\HumanBloodPeasant.mdl
Special Effect - Destroy (Last created special effect)
Unit Group - Remove tempunit from tempgroup2
Unit - Move (Casting unit) instantly to temppoint

I belive that because i used variables for everything it won't create memory leaks, but i just wanted someone to check it for me. If this doesn't leak then i know i have a proper understanding of preventing memory leaks, if it does then obviously i dont. Thanks guys!

Edited by Blade.dk. Reason: Trigger tags.
09-20-2006, 08:13 PM#2
Captain Griffen
There is no point in using a local variable instead of a global in GUI if there are no waits.

Distance between (Position of (Casting unit)) and (Target point of ability being cast)

Leaks.

temppoint leaks. Never destroyed.

Suggest you read some tutorials, as you don't appear to understand what you are doing, which is vital.
09-20-2006, 08:16 PM#3
Blade.dk
Learn to use the [trigger] tags.
09-20-2006, 08:18 PM#4
DurotarLord
I tried destroying the variables afterwards, but when i did that it could only run the trigger once. i have read some tutorials on the topic and never came across anything on the "Distance Between" function. As for the local your absolutely right, i originally planned on having waits but in the end decided against it. Thanks captain, youve been a big help lately. :)
09-20-2006, 08:23 PM#5
Captain Griffen
Region centered at ((Position of (Casting unit)) offset by (Real((Integer A))) towards (Facing of (Casting unit)) degrees)

Also leaks twice.

Quote:
Originally Posted by DurotarLord
I tried destroying the variables afterwards, but when i did that it could only run the trigger once.

No, you don't destroy the variables, but the objects that the variables point to.
09-20-2006, 08:28 PM#6
DurotarLord
I assume it leaks at "Position of (Casting unit))" and "offset by (real((integer A)))"
09-20-2006, 08:29 PM#7
Captain Griffen
Creates two new locations, yes.

If you can, I'd suggest learning JASS, so you can throw away locations pretty much for good and use co-ordinates.
09-20-2006, 08:59 PM#8
The)TideHunter(
Ofc, griff is right again, using X/Y/Z is much better than handling locations, yes locations have some advantages, but coords are not handles, they dont leak.
Its easier to use them, and is just better! Rawr!

Position of UNIT always leaks, set it to a location, then use:

Trigger:
Custim Script: call RemoveLocation(SomeLocation)

Remember, if you set a variable to a location, then you dont destroy and set it to another, then destroy, dont hope it will remove them both, you need to destroy it each time you'v finished using it before you should set it again.
09-21-2006, 08:25 PM#9
aquilla
A memory leak is when you create something, making it take up memory, but then is never removed where it should be or the variable/whatever which is referring to it is lost
Trigger:
Slash
Collapse Events
Unit - A unit Starts the effect of an ability
Collapse Conditions
(Ability being cast) Equal to Slash
Collapse Actions
Custom script: local unit udg_tempunit
Set tempunit = (Casting unit)
---- a location which is never removed: ----
Set temppoint = (Target point of ability being cast)
---- location leaks: ----
Special Effect - Create a special effect at (Position of (Casting unit)) using Abilities\Spells\Orc\MirrorImage\MirrorImageCaster.mdl
Special Effect - Destroy (Last created special effect)
---- two locations leak + HORRIBLE LOOP: ----
Collapse For each (Integer A) from 1 to (Integer((Distance between (Position of (Casting unit)) and (Target point of ability being cast)))), do (Actions)
Collapse Loop - Actions
---- a region and two locations leak: ----
Set tempregion = (Region centered at ((Position of (Casting unit)) offset by (Real((Integer A))) towards (Facing of (Casting unit)) degrees) with size (150.00, 150.00))
---- a group leaks + unneccesary use of random player: ----
Set tempgroup = (Units in tempregion matching ((Owner of (Matching unit)) Not equal to (Random player from (All allies of (Owner of (Casting unit))))))
Unit Group - Add all units of tempgroup to tempgroup2
Custom script: call SetUnitAnimationByIndex(udg_tempunit, 6)
Collapse For each (Integer B) from 1 to (Number of units in tempgroup2), do (Actions)
Collapse Loop - Actions
---- why loop this way with random unit? not needed ----
Set tempunit = (Random unit from tempgroup2)
Unit - Cause (Casting unit) to damage tempunit, dealing ((16.00 + (4.00 x (Real((Level of Slash for (Casting unit)))))) + (0.10 x (Real((Agility of (Casting unit) (Include bonuses)))))) damage of attack type Spells and damage type Normal
---- location leak: ----
Special Effect - Create a special effect at (Position of tempunit) using Objects\Spawnmodels\Human\HumanBlood\HumanBloodPeasant.mdl
Special Effect - Destroy (Last created special effect)
Unit Group - Remove tempunit from tempgroup2
Unit - Move (Casting unit) instantly to temppoint
Right, well I don't see why you loop through each "1" distance, eg a distance of 500 would result in 500 regions, 1000 locations and 500 groups leaking . Not only that, but it would be unbelievably slow as well since you use everything "random". You see, when you pick a random unit for example, it loops through the entire group and then returns a unit based on that. While for eg First unit of group is a native; "1 line of code" instead of 10 with a slow loop

You've come a bit along the way by storing the handles that leak,
but to take care of a memory leak you need to remove it once you're done with it:
Trigger:
Set temppoint = (Position of (Casting unit))
Special Effect - Create a special effect at temppoint using Abilities\Spells\Orc\MirrorImage\MirrorImageCaster.mdl
Special Effect - Destroy (Last created special effect)
Custom script: call RemoveLocation(udg_temppoint)
to fix the other leaks it's the same thing that goes except for the custom script. Below is how to destroy a unit group and region (a region is actually a rect(angle) in jass) respectively:
Trigger:
Custom script: call DestroyGroup(udg_tempgroup)
Custom script: call RemoveRect(udg_temprect)