Friday, 2024-04-19, 2:52 PM


Main
Registration
Login
Welcome Guest | RSS  
[ New messages · Members · Forum rules · Search · RSS ]
  • Page 1 of 1
  • 1
Forum moderator: Hanky, Fireeye  
Clan NgO Forums » Discussions » Junk Yard » [Tutorial] Memory Leaks (Teach'in and stuff.)
[Tutorial] Memory Leaks
HankyDate: Monday, 2008-08-25, 7:10 AM | Message # 1
Lieutenant colonel
Group: Moderators
Messages: 116
Reputation: 9
Status: Offline

Leak Tutorial
Made by Clan NgO

You maybe already heard from leaks. Leaks can cause your map to lag, thus a black screen appears after playing your map.
That's because all the leaks which got created have to be cleaned/destroyed. You can fix them easily, even with out JASS experience!
But first off, I'd like to explain what a memory leak in warcraft III is.

What are leaks?

Leaks are handles which are not destroyed and just rest in your memory. It's like in school. You get many information thrown at your head, but you
automaticly forget about everything. So what would happen if we wouldn't have this "forget function" ? -Right! Our heads would overstress and getting slow.
In Warcraft III it's "basicly" the same, having more useless information, which is stored in the memory causes slow calculations.
Note that slow computers are faster affected from memory leaks than faster/better computers.

What leak in Warcraft 3?

Every handle can leak. Handles are:

Quote
# type boolexpr, button, camerafield, camerasetup, destructable, effect, event, fogmodifier, fogstate, force, gamecache, group, image, item itempool, leaderboard, lightning, location, mapvisibility, multiboard, player, quest, rect, sound, region, terraindeformation, texttag, timer, timerdialog, trackable, trigger, ubersplat, unit, widget, weathereffect

Lots of handles! But don't worry, many of this handles you will never have to clear up.
Handles which won't leak, such as Integers, Reals, Booleans & Strings.

How can I clear up those leaks?

Well you have to destroy them with JASS functions. But don't be scared if you are a GUI'er because it's not hard. For every handle type is a different destroy/remove function. Here is the list of the functions:

Now I make some examples to show you how to use them.
In the first example I remove a effect handle:

In the first example I've created a special effect and the action "Destroy (effect)".
But we don't want to destroy the special effect right after it was created! So we save the effect in a special effect variable.
Go to your Variables Editor ( CTRL + B ) and create a special effect with a desired name. In this example we've called it "Name".

After you're done with this, save the effect in your variable. Take a look at this example:

Now to remove it create a new action, which should look like this. Of course you can also put that action into your first trigger:

Now I'm gonna show you an another example. First off, I'll show you what creates the leak.
And after that how to remove it.

Here you can see a typical leak. The unit got created at location of the middle of map. The location did not got removed, thus a leak is born.
But you can easily fix that. First I create in the variables editor location variable. In this example I name the variable Loc.

As you can see, I simply created a variable "Loc" of type location. I set it up to the middle of the map.
After the unit got created I removed it again with the JASS function "RemoveLocation(whichLocation)".
You might ask why I've put a "udg_" before the name of the location. GUI created globals variable got the prefix "udg_" at the beginning of it's name.
"udg" stands for "User Defined Global" with this prefix blizzard just wanted to highlight that it's a global user variable.

There are also variables with other prefixes. For example the variables that Blizzard used in their scripts got the prefix
"bj_" and Sound variables got the prefix "gg_snd" etc.!

With the Jass New Gen Pack you can declare global variables without any prefix.

How do I clean local variables correctly?

Beside to the globals there are the locals. Locals are variables who are just created inside a function and can't used in other functions without any attach functions.
Many guys who use locals think that just destoying the handles of the locals would be all. No it isn't.
Also when you remove this handles they are still in cache cause the locals still got them.
There a easy example:

This is a typical mistake. Many guys don't know that the local "a" and "e" will be still in cache. But with two
easy and short lines of JASS also this leak will be cleaned up.

After you nullified the locals there will be no more leaks. This also should be made with globals if they aren't used anymore.
But remember you don't need to nullify the parameter inside of a function and if you got a function that return something you also have to destroy and to null the locals that arent needed anymore. It should look like this:

How I can avoid the boolexpr leak?

What would be Warcraft 3 without bugs? Right, it wouldn't be Warcraft 3! So there is a bug with the filter function but you can easily avoid it.
Here an example:

How you see I made a null at the boolxpr parameter. Well how you maybe expect, this will leak.
But you can also avoid this easily. Just make a filter function like this:

After you created this filter function you the group function should look like this:

And voilá your function is clean.

How I can avoid leaks of the GameCache?

To clean up stuff inside the gamecache there are several functions:

This are the standart functions to clean up single data.

With this function you clean a whole mission. That means all data you saved with the same missionKey string
will be cleared up. This function is good when you have saved many datas at the same missionKey and you dont want to clear up extra every data.

This function is there to clear up the whole cache.

Hint: You can just initialize 255 gamecaches.



This tutorial were made by:
  • Hanky
  • Darkt3mpl3r

    Greeting: WaRadius, Toadcop, JonNny and the whole NgO Clan.

    Note: The attached file is the tutorial as html file.

  • Attachments: LeakTutorial.7z (49.9 Kb)



    Made by Smoe reworked by GiR aka Darkt3mpl3r
     
    FireeyeDate: Thursday, 2008-08-28, 6:40 PM | Message # 2
    Private
    Group: Moderators
    Messages: 16
    Reputation: 5
    Status: Offline
    About the 255 Gamecaches, there's also a bug if you've saved 255 gamecaches in offline mode (e.g. when you play an offline campaign), you won't be able to create any gamecache anymore (to my knowledge, gonna post a link to the thread on wc3c later)

    ---Edit---
    found it >>> here <<<


     
    TheCheeseLoverDate: Wednesday, 2009-07-22, 2:57 AM | Message # 3
    Sergeant
    Group: Users
    Messages: 22
    Reputation: 0
    Status: Offline
    Hey!

    Great tutorial :D.

    I have a question about the triggers leak. Do we need to destroy a trigger when we used it for the last time or we can destroy it when all the code as been used one time or more?


    Yay I have a signature. You suck. :D
     
    FireeyeDate: Friday, 2009-07-24, 1:51 PM | Message # 4
    Private
    Group: Moderators
    Messages: 16
    Reputation: 5
    Status: Offline
    As far as i got you, you're telling me, that you use dynamic triggers?! Those things are most likely useless unless you use the in a damage detection system.
    I personally would never destroy a trigger, as it can fuck up the entire game randomly.
    Or if you want to destroy a trigger, use it on a trigger with only Event and Condition, no Action.


     
    TheCheeseLoverDate: Friday, 2009-07-24, 3:13 PM | Message # 5
    Sergeant
    Group: Users
    Messages: 22
    Reputation: 0
    Status: Offline
    Thanks. Woohoo another question! What is a dynamic trigger?

    Yay I have a signature. You suck. :D
     
    FireeyeDate: Friday, 2009-07-24, 7:45 PM | Message # 6
    Private
    Group: Moderators
    Messages: 16
    Reputation: 5
    Status: Offline
    A dynamic trigger, is a trigger you're creating and destroying on the fly, meaning at run time of the map.

     
    TheCheeseLoverDate: Saturday, 2009-07-25, 5:26 PM | Message # 7
    Sergeant
    Group: Users
    Messages: 22
    Reputation: 0
    Status: Offline
    No I don't really use dynamic triggers except for my own map when I do Init trigger.

    Yay I have a signature. You suck. :D
     
    Clan NgO Forums » Discussions » Junk Yard » [Tutorial] Memory Leaks (Teach'in and stuff.)
    • Page 1 of 1
    • 1
    Search:

    Clan NgO © 2024Powered by uCoz