Triggers - Memory Leaks and Custom Scripts

Tzirrit

New Member
Reaction score
7
That's what i have feared. So i'd have to save that random point in a variable and either destroy it afterwards, or just keep overwriting it with new random positions.. because i use that quite often for wandering creeps, patroling npcs and so on? Great.. lots of klicking to be done ;(
 

quraji

zap
Reaction score
144
You need to save it in a variable and destroy it, every time you use it. Points don't remove themselves from memory just because you stored a new one in the variable.
 

Tzirrit

New Member
Reaction score
7
Ok, i wasn't sure about this, thought overwriting would be enough. Thanks for making it clear.

edit: finally.. my map should be leak free.. didnt even take as long as i thought (zomg - only 4 hours) and i optimizied some triggers while i was at it. +rep for this nice tut that made me do it *g*
 

PurgeandFire

zxcvmkgdfg
Reaction score
508
I didn't read all of the tutorial, but I skimmed through... Nice job, but I have a question:

Do you have to always set a variable as a point and then place the special effect or is it ok if you use things such as regions or coordinates? :D

Nice tutorial... +rep :D
 

emjlr3

Change can be a good thing
Reaction score
395
reals dont leak, locations of regions do
 
B

Banana

Guest
I'm wondering why do we need to call functions to clear leaks. Wouldn't setting the variable to null or nothing or something similar accomplish this without calling a function?
 
N

Niko

Guest
i read somewhere else that random numbers can leak... but that would be included in the reals/ints etc correct? so i'm assuming they don't because i use an integer variable for most of my random numbers. just checking!
thanks
niko

PS almost forgot... sometimes i have conditions that check the distance between the positions of two units... do these checks require a variable. I'm guessing the game doesn't actually store anything so i would assume there are no memory problems in conditions
 

PurgeandFire

zxcvmkgdfg
Reaction score
508
@emjlr3: Thanx!

@Banana: Not always nulling can clear leaks, you must perform other functions or actions etc. as well to stop it:
eg: call RemoveLocation( a )

@Niko: Nope, reals and integers don't leak as emjlr3 said... Random Numbers are included as int/real.
For the second problem, I guess you could store it as a variable (Here is it in GUI):
Code:
set Distance = (Distance between <blablb> and <ballablbalbla>)
But I don't know if it is actually necessary. ;)
 
S

shadowvzs

Guest
i dont know this not leakable if i kill under 1 sec 10 creep? because 10 special effect and 1 removing but variable overwrited, or how will be this?
Code:
reSpawn
    Events
        Unit - A unit owned by Neutral Hostile Dies
        Unit - A unit owned by Player 11 (Dark Green) Dies
    Conditions
        ((Triggering unit) is Summoned) Equal to False
        ((Triggering unit) is A structure) Equal to False
        (Unit-type of (Triggering unit)) Not equal to Chocobo
    Actions
        Custom script:   local item ItemA
        Set Tempory_nr[26] = (Random integer number between 1 and 100)
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                Tempory_nr[26] Less than or equal to item_drop_rate
            Then - Actions
                Item - Create (Random level (Random integer number between 0 and 10) Purchasable item-type) at ReSpawnPoint
                Custom script:   set ItemA = bj_lastCreatedItem
            Else - Actions
        Set ReSpawnPoint = (Position of (Triggering unit))
        Special Effect - Create a special effect at ReSpawnPoint using Objects\Spawnmodels\Undead\UndeadDissipate\UndeadDissipate.mdl
        Custom script:   call RemoveLocation(udg_ReSpawnPoint)
        Set SpecialEffect[0] = (Last created special effect)
        Wait 3.00 seconds
        Custom script:   call DestroyEffect (udg_SpecialEffect[0])
        Wait 40.00 seconds
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                ItemA Not equal to No item
                (ItemA is owned) Not equal to True
            Then - Actions
                Custom script:   call RemoveItem(ItemA)
                Custom script:   set ItemA = null
            Else - Actions
        Wait (((Real((Level of (Triggering unit)))) + 1.00) / 2.00) seconds
        Set ReSpawnPoint = ((Center of (Entire map)) offset by (CreepX[(Custom value of (Triggering unit))], CreepY[(Custom value of (Triggering unit))]))
        Unit - Create 1 (Unit-type of (Triggering unit)) for (Owner of (Triggering unit)) at ReSpawnPoint facing Default building facing degrees
        Custom script:   call RemoveLocation(udg_ReSpawnPoint)
        Unit - Set the custom value of (Last created unit) to (Custom value of (Triggering unit))
        Animation - Play (Last created unit)'s birth animation
 

SerraAvenger

Cuz I can
Reaction score
234
emjlr3 said:
Memory Leak: the leakage of handle objects, or in other words, basically whenever you create something or reference something, other than integers the game loses it’s location, thus causing a leaked piece of memory. Now granted these are cleaned at the end of the game, but if enough pile up during play without being removed, it can cause serious lag to the players, ranging from a little here and there, to complete un-playability, neither of which is wanted.

I would descipt it as:
SerraAvenger said:
Memory Leak:
A memory leak occurs, when you loose the last pointer to an object that actually uses memory. As you can no longer refer to that object then, you cannot destroy and so you cannot free the memory you allocated by creating it. This memory can no longer be used, so you have small to great perfomance losses.
Note that as long you still can refer to the object (due to variables or functions), the memory it occupies will not leak. Still, you should destroy every object as soon as you no longer need it; saving in variables will need even more memory than a simple memory leak. Still you can free the memory and reduce the needed ressources.

You mainly seperate between 2 forms: Normal leaks, and Bad leaks. A bad leak is a leak that happens multiple times (in a loop , in a trigger fireing very often ). Normal leaks are such that only occur once ( In a trigger on map initiallisation creating a point for A unit that shall patrol to that point ).

Memory leaks only at the moment you loose the last pointer to the object allocating it, not before and not after. And an object ( location, p.e. ) cannot leak. It is the memory that does, and an object cannot have a leak, it is the code that has.
Longer, but more correct and informative.
Would remove some great missunderstandings, too.
Greetings, Serra


EDIT:
@Shadowvyz:
Yes it will leak. Set it to a local variable instead.
 
O

Object

Guest
Interesting... it makes me wonder why they did not just build these solutions into the GUI triggers... :nuts:
 

SerraAvenger

Cuz I can
Reaction score
234
Interesting... it makes me wonder why they did not just build these solutions into the GUI triggers... :nuts:

The same reason for doing this crap:
Code:
DestroyCondition
DestroyBoolExpr
DestroyDamageOptions
DestroyDefeatCondition                                      
DestroyEffect
DestroyFilter
DestroyForce
DestroyLightning
DestroyGroup
DestroyImage
DestroyLeaderboard
DestroyMultiboard
DestroyQuest
DestroyTimer
DestroyTextTag
DestroyUbersplat
But
Code:
RemoveLocation
- I would call it inattention and lazyness...
 

darkRae

Ueki Fan (Ueki is watching you)
Reaction score
173
I have a question that I've been eager to ask.
Does the custom script DESTROYS the variable or EMPTIES it?
So if we have (for example) several point leaks in different triggers, do we have to create another variable or use the previous point variable?

Hi anyway, I'm new here, but not to WE
 
S

Sunny_D

Guest
if you mean variables that you define within the trigger editor (global variables), then you still can use the variable itself for later other points. so in your words - it "empties" the variable.

example, you create a point variable TempLoc that you can use for all your leak-removings in your triggers - as long as you dont have waits in between, but thats of course another story.

Set TempLoc = ...
Unit - create Unit at TempLoc // or whatever else..
Custom script - call RemoveLocation (udg_TempLoc)

you can use the TempLoc variable again and again that way :)

PS: ye, i know its late, but meanwhile no1 else answered and i saw you edited your post just yesterday, so.... :D
 
A

AK-47Pirates

Guest
I used Tinki3's creep revival system, and in my RPG, I'd figure it is gunna leak several hundred times, but I don't know how to even begin fixing this leak:

Code:
Creep Revival System Initialization
    Events
        Map initialization
    Conditions
    Actions
        Unit Group - Pick every unit in (Units in (Playable map area) owned by Neutral Hostile) and do (Actions)
            Loop - Actions
                Set Integer = (Integer + 1)
                Unit - Set the custom value of (Picked unit) to Integer
                Custom script:   set udg_Creep_X[udg_Integer] = GetUnitX(GetEnumUnit())
                Custom script:   set udg_Creep_Y[udg_Integer] = GetUnitY(GetEnumUnit())

Code:
Reving Creeps 1 By 1
    Events
        Unit - A unit Dies
    Conditions
        ((Owner of (Triggering unit)) Equal to Neutral Hostile) and (((Triggering unit) is Summoned) Not equal to True)
    Actions
        Wait 60.00 game-time seconds
        Unit - Create 1 (Unit-type of (Triggering unit)) for Neutral Hostile at ((Center of (Entire map)) offset by (Creep_X[(Custom value of (Triggering unit))], Creep_Y[(Custom value of (Triggering unit))])) facing (Random angle) degrees
        Unit - Set the custom value of (Last created unit) to (Custom value of (Triggering unit))

How would I do this?
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top