Page 1 of 3 123 LastLast
Results 1 to 15 of 35

Thread: Memory Leak

http://idgs.in/22550
  1. #1
    MimiHitam's Avatar
    Join Date
    Oct 2006
    Posts
    9,242
    Points
    16,524.95
    Thanks: 14 / 58 / 42

    Exclamation Memory Leak

    Memory Leak Tutorial By - Rad from thehelper.net


    What is a Memory Leak?

    A memory leak is a small bit of information that is not removed after it is used. Converting anything to a non-official variable can cause a memory leak. Point leaks are using center/random points in memory leaks. Group leaks are when you use a unit, player, or destructible GROUP function (Without variables for the group). Region leaks are whenever you convert a 'point with size' or an area, that is not already a variable or preset, to a region.


    Symptoms of a Memory Leak:

    StarServer Splits
    .....Server Splits happen whenever alot of memory leaks are detected, they can be very random or always happen at the same time. They can range from everyone except you disconnecting, to having a few players disconnect. If you can find out if the disconnected players are still in the game together then that is solid proof of a server split.
    StarHeavy Lag
    .....If your map starts lagging, usually over time, first check to see if something wrong with a trigger. Say you spawn one skeleton every second of the game, it wont lag for awhile but if you dont kill them off it will. A good way to test is have a -killall trigger to check if they are simply overspawning. If this doesnt help, its probrably a memory leak.
    StarRandom Disconnections
    .....First make sure they are not just leaving, secondly if everyone except you leaves at once, it can either be you randomly disconnecting or a server split. As I said its nice to stay in contact with those who disconnect just to check.
    StarSlow Performance
    .....If its not exactly laggy, but is running unusually slow... ask the other people in your game if it seems slow. As long as there isnt a problem spawning or something that can effect your video/sound card to create lag its possible that its from a memory leak.
    StarTriggered-Spell Lag
    .....Not only for spells, but any trigger that has alot of possible memory leaks (List below). If it happens when this fires, and your sure of it, use this tutorial to get rid of as many as possible!




    Types of Memory Leaks:

    - Points: These are the most dangerous when making spells and movement systems with keyboard. Whenever you use the position of an object or a point of a region (Whether it be random or center), and even coordinates, they create a memory leak.
    - Groups: Also a common leak, whenever you use "Unit-Group - Pick every unit..." (Also Player and Destructible etc) and you do not use a variable as the group, it will leak.
    - Regions: Converting a point with a size to a region, or anything that creates an 'area' without using a region (or preset) will create a memory leak.
    - Special Effects: If you do not remove a special effect (Done through a trigger, spells do not leak) it will leak. Even if the spell is finished, the data is still there.
    - Strings: Strings are very minor, as they are reused. Once you use "Hi" as a string, every time you use "Hi" it uses the same data, it will not leak... but if you display random messeges (Tips that are preset are fine) it might add up, but probrably not...


    Restoring the Memory:

    Points: The easiest way to remove a point leak is by using a universal point variable. As long as there are no waits which seperate the declaring of the variable to the use of the variable you only need one variable. If you do use a wait you need a seperate global - If not another trigger may remove its data before it is used.

    Leak:
    Code:
    Unit - Create 1 footman at (Center of (Region A)) for Neutral passive facing default building degrees

    Fix:
    Code:
    Set Point = (Center of (Region A))
    Unit - Create 1 footman at (Point) for Neutral Passive facing default building degrees
    Custom Script: call RemoveLocation(udg_Point)


    Groups: These are fairly easy to remove, so long as they do not use waits as well. It was suggested to only use waits in integer loops by a few people higher than me.

    Leak:
    Code:
    Unit Group - Pick every unit in (Units owned by (Player 1)) and do (Unit - Kill (Picked unit))

    Fix:
    Code:
    Custom Script: set bj_wantDestroyGroup = true
    Unit Group - Pick every unit in (Units owned by (Player 1)) and do (Unit - Kill (Picked unit))

    NOTE: To remove player group leaks, replace "Group" with "Force".

    Fix 2: More efficient
    Code:
    set UnitGroup = (Units owned by (Player 1))
    Unit Group - Pick every unit in UnitGroup and do (Unit - Kill (Picked unit))
    Custom Script: call DestroyGroup(udg_UnitGroup)


    Regions:
    Regions are usually very minor leaks, unless you customize your spells like War Stomp they shouldnt be a problem. You should only need one variable for these, as they are not as needed to store.

    Leak:
    Code:
    Unit - Cause (Casting unit) to damage ((Point) with size 500, 500) dealing 500 damage using attack type Normal and damage type Normal

    Fix:
    Code:
    Set (Region) = (Point) with size 500,500
    Unit - Cause (Casting unit) to damage ((Point) with size 500, 500) dealing 500 damage using attack type Normal and damage type Normal
    Custom Script: call RemoveRect(udg_Region)

    NOTE: Point would be a variable as this would leak both a point and a region (Like most region leaks)

    Special Effects:
    These are easy to fix, just destroy the effect with the GUI function "Destroy Effect", you may need a variable for this. It will still display its death animation, if it has none it will usually last roughly 5 seconds.

    Leak:
    Code:
    Special effect - Create special effect at (Point) using (Units\Human\Footman\Footman.mdx)

    Fix:
    Code:
    Special effect - Create special effect at (Point) using (Units\Human\Footman\Footman.mdx)
    Set (Footman Effect) = (Last Created Special Effect)
    Wait 5 seconds
    Special effect - Destroy (Footman Effect)

    NOTE: If your effect shouldnt disappear, sacrifice the memory leak... just dont use to many!

    Strings:
    You cannot do anything about string variables (To my knowledge), if you can I'm sorry I do not have the answer.


    FAQ's:

    .....How do variables help?
    Using a variable to store a piece of information is the only way to call upon that information in order to remove it. Sometimes they are automatically stored, example the (Last created...) function will store the information, and you do not need a variable. You still need to remove the (Last created...) after use, though.

    .....How do you use the function tags?
    Most, if not all of the memory leaks have a different function tag. They all basically use call Remove"Function"(udg_Your_Variable) (Also call Destroy"Function"(udg_Your_Variable) and with this, you can find a JASS tool that has a list of function names and find out how to remove them yourself!

    .....What are some guidelines to reducing memory leaks?
    Memory leaks are most common when using periodic events, especially small ones such as (Time - Every .01 seconds of the game). Keep in mind using such a small value means that your FPS is higher than 100 with that event, most peoples arent... if they are they would hardly notice if you used (Time - Every .05 seconds of the game). It might not seem much different, but .01 happens 5 times more than .05, and you cant tell the difference anyways!

    Also, using groups (mainly unit groups) are common memory leak generators. Theres a solution above, of course.

    .....How do I check if my triggers leak?
    If your trigger uses a periodic event under 5.00 seconds, then you need to check for any of the common leaks (Listed above). Also check ones with any group or integer loops. Spells are also very common, mainly for leaking points... so double check those too. Its a good idea to use the Object Manager (F11) to find where functions loop or you use unit/player groups.

  2. Hot Ad
  3. #2
    M4Ste12's Avatar
    Join Date
    Nov 2006
    Posts
    3,188
    Points
    3,791.90
    Thanks: 0 / 2 / 2

    Default

    Nice Guide, akhirnya gw tau jenis2 memory leak.

    Nanya donk, sebenernya memory leak tuh cman buat triger2 yang pake periodic event ajah ya? klo trigger biasa bisa leak gak si? (misalnya buat triger yang cman jalan tiap cast spell, ato tiap ada unit masuk ke area)

  4. #3
    aVaTaR_EnGiNE's Avatar
    Join Date
    Jan 2007
    Location
    Database Error
    Posts
    170
    Points
    191.90
    Thanks: 0 / 0 / 0

    Default

    bisa aja...
    kyk contoh di atas...

    Special effect - Create special effect at (Point) using (Units\Human\Footman\Footman.mdx)

    ntu akan leak klo efek ntu ga di destroy...

    - Points: These are the most dangerous when making spells and movement systems with keyboard. Whenever you use the position of an object or a point of a region (Whether it be random or center), and even coordinates, they create a memory leak.
    - Groups: Also a common leak, whenever you use "Unit-Group - Pick every unit..." (Also Player and Destructible etc) and you do not use a variable as the group, it will leak.
    - Regions: Converting a point with a size to a region, or anything that creates an 'area' without using a region (or preset) will create a memory leak.
    - Special Effects: If you do not remove a special effect (Done through a trigger, spells do not leak) it will leak. Even if the spell is finished, the data is still there.
    - Strings: Strings are very minor, as they are reused. Once you use "Hi" as a string, every time you use "Hi" it uses the same data, it will not leak... but if you display random messeges (Tips that are preset are fine) it might add up, but probrably not...
    yg gw quote nih yg bisa bikin leak...jadi gak cuman periodic aja...klo tiap cast, tapi lupa remove benda2 di atas ni, bisa leak jg...

  5. #4
    M4Ste12's Avatar
    Join Date
    Nov 2006
    Posts
    3,188
    Points
    3,791.90
    Thanks: 0 / 2 / 2

    Default

    OK de

    eh, klo tipe unit tuh isa leak gak si? koq gw perhatiin orang suka bikin variable buat unit jg (casternya biasanya)

  6. #5
    valkemiere's Avatar
    Join Date
    Oct 2006
    Location
    In my Rainbow Castle
    Posts
    1,874
    Points
    5,111.21
    Thanks: 65 / 32 / 31

    Default

    kan uda ada program leak check?
    donlot aja di hive

  7. #6
    aVaTaR_EnGiNE's Avatar
    Join Date
    Jan 2007
    Location
    Database Error
    Posts
    170
    Points
    191.90
    Thanks: 0 / 0 / 0

    Default

    hmm...klo unit...biasanya klo spell yg multi-instance able pake local variable buat unit...
    klo yg dipake local variable, terakhirnya harus di set = null...klo ga leak...
    mm...meskipun pake global variable, biar aman di set null jg aja di akhir spell... (yg terakhir ni gw ga tau pengaruh ato ga) --"

  8. #7
    M4Ste12's Avatar
    Join Date
    Nov 2006
    Posts
    3,188
    Points
    3,791.90
    Thanks: 0 / 2 / 2

    Default

    kan uda ada program leak check?
    donlot aja di hive
    percuma kan klo tau ngeleak tapi gak tau cara betulinnya ^^

    hmm...klo unit...biasanya klo spell yg multi-instance able pake local variable buat unit...
    klo yg dipake local variable, terakhirnya harus di set = null...klo ga leak...
    mm...meskipun pake global variable, biar aman di set null jg aja di akhir spell... (yg terakhir ni gw ga tau pengaruh ato ga) --"
    yah, tapi kan spell MUI biasanya pake JASS, jadi biasanya gka masalah di Leak. Gw liat di Leak check si meskipun gak dibikin null, gak masalah...

    Kita bisa bikin spell yang MUI pake trigger gak si? klo pake JASS kan ada Local Variable, nah, bukannya di Trigger bisa diganti pake array yah? bikin ajah arraynya sesuai ama player, jadi Var(1) buat player merah, Var(2) buat biru, dsb...

  9. #8
    h_e_L_p_m_e's Avatar
    Join Date
    Oct 2006
    Location
    Oceanic Cafe, Segarra, Jetski Cafe, Vin+, Le Bridge, AMPM
    Posts
    16,067
    Points
    67,601.50
    Thanks: 2 / 41 / 15

    Default

    gw kasih thanks tuh..menurut gw thread lw ini sangat penting......
    I LOVE INDOGAMERS

  10. #9
    M4Ste12's Avatar
    Join Date
    Nov 2006
    Posts
    3,188
    Points
    3,791.90
    Thanks: 0 / 2 / 2

    Default

    nanya lagi donk!
    klo pake Picked Unit itu bisa ngeleak gak si? ato harus dimasukin ke variable picked unitnya??

  11. #10
    aVaTaR_EnGiNE's Avatar
    Join Date
    Jan 2007
    Location
    Database Error
    Posts
    170
    Points
    191.90
    Thanks: 0 / 0 / 0

    Default

    picked unit?
    abisnya unit group - pick all players in <unit group>
    biasanya emank dikasih destroy lastcreated unit group gitu...
    coz masalah unit group ni mank bisa bikin leak klo dah berkali2 dijalanin...

  12. #11
    M4Ste12's Avatar
    Join Date
    Nov 2006
    Posts
    3,188
    Points
    3,791.90
    Thanks: 0 / 2 / 2

    Default

    bukan pick itu.
    tapi yang di action 'pick every unit in unit group'. abis itu kan kita bisa make fungsi picked unit buat nge-refer ke unit yang lagi di proses (pas loopnya)... nah klo kita misalnya pake fungsi 'picked unit' bakal leak gak? ato kita harus masukin ke variable > VarUnit = picked unit gitu??

  13. #12
    aVaTaR_EnGiNE's Avatar
    Join Date
    Jan 2007
    Location
    Database Error
    Posts
    170
    Points
    191.90
    Thanks: 0 / 0 / 0

    Default

    err...klo itu...setau gw sih ga...
    klo dah ada picked unit ya ga usah tambahin variable lagi lah...
    kcuali lw mw ngambil satu aja dari picked units ntu...
    baru pake variable...

  14. #13
    rizzuh's Avatar
    Join Date
    Oct 2006
    Location
    Bandung, Indonesia, Indonesia
    Posts
    671
    Points
    1,308.90
    Thanks: 2 / 14 / 10

    Default

    1 tips mudah untuk menghindari leak ...
    selalu masukan hal2x yang berupa location, unit, special effect, ( dan jenis2x pada post pertama ) kedalam suatu variable, dan gunakan variable tersebut dalam fungsi2x yg kamu buat.

    buat yang pick every unit ....
    sebenernya kamu tinggal masukin ini sebelum pake fungsi picked unit

    set bj_wantDestroyGroup = true
    ---> pake custom script dah gitu ketik persis ( case sensitive; kl salah ntar error ) seperti yang ada di atas dala custom scriptnya

    yang bikin leak itu grupnya bukan unitnya, pake picked unit ngga masalah.

  15. #14
    aVaTaR_EnGiNE's Avatar
    Join Date
    Jan 2007
    Location
    Database Error
    Posts
    170
    Points
    191.90
    Thanks: 0 / 0 / 0

    Default

    1 tips mudah untuk menghindari leak ...
    selalu masukan hal2x yang berupa location, unit, special effect, ( dan jenis2x pada post pertama ) kedalam suatu variable, dan gunakan variable tersebut dalam fungsi2x yg kamu buat.
    hmm...iya sih...tapi klo local variable kan musti di null kan abis dipake yah?
    biasanya banyak yg lupa disini...
    err....
    set bj_wantDestroyGroup = true
    ini ditaruh mana yah?
    sebelumnya
    Unit Group - Pick every unit in units group ?

  16. #15
    M4Ste12's Avatar
    Join Date
    Nov 2006
    Posts
    3,188
    Points
    3,791.90
    Thanks: 0 / 2 / 2

    Default

    ini ditaruh mana yah?
    sebelumnya
    Unit Group - Pick every unit in units group ?
    klo gak salah si sebelon...
    tapi gw lebih seneng pake 'destroy group' daripada pake gituan...

    BTW, semua variable harus di null? termasuk variable real jg? kadang2 gw pake real buat angle gitu... gw cman pake null buat variable unit, sementara klo location ama group biasanya gw destroy/remove...

Page 1 of 3 123 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •