Memory Leaks

From WarCraft3

< wc3
Jump to: navigation, search

Memory leaks, or simply leaks, are bits of unused, unreferenced memory in a map. Memory leaks often[weasel words] sit there and pile up. Over time, more and more memory is consumed. Performance will be affected (lag will increase [citation needed]), the map could possibly[weasel words] freeze, or crash. [citation needed]

It is a good practice[weasel words] in mapping to remove memory leaks whenever possible. When using GUI, there are some leaks that are unavoidable.[citation needed]

The most common leaks are actual object leaks (locations, groups, etc.)[citation needed]. However, there are such things as handle reference leaks[citation needed], and some leaks that just come from natives[citation needed]. Most[weasel words] leaks coming from certain[weasel words] natives are unpreventable[citation needed].

These are the objects that most commonly cause leaks in mapping[citation needed], and the natives used to destroy them:

However, almost[weasel words] every type that can be created can be leaked.

Contents

Removing Leaks

Tutorials regarding the location and removal of memory leaks:

SerraAvenger's LeakLess will fix your map's leaks for you. Be sure to read the instructions carefully.

Specific Memory Leaks

There are some[weasel words] things in Jass that are known for certain[weasel words] to leak[citation needed].

Handle Reference Leak

Agents in Jass are reference counted[citation needed]. Because local variables don't lower their value's reference count when the variables stop existing[citation needed] (i.e. when the function instance ends), they must be manually set to point to something else before that in order to lower the reference count. Null can be used as the new value, as its reference count won't increase[citation needed] nor will it be destroyed, because it isn't an existing object. If an agent's reference count never reaches 0 after destruction, its handle will never be recycled.

Returning a local agent will not lower the reference count[citation needed], and returning ends a function's execution. A global must be used to take the value of the local agent. The agent must then be nulled, and the global returned.[citation needed]

Example

globals
    unit RetUnit
endglobals

function ReturnUnit takes nothing returns unit
    local unit u = //...
    //Some stuff.
    set RetUnit = u
    set u = null
    return RetUnit
endfunction

Persistent References Leak

If a reference to an agent is kept after the agent has been removed from the game, the reference count is not 0 and the agent's handle id is not recycled immediately. It is known that[weasel words] the agent's handle id will be recycled when the reference count receeds to 0[citation needed], but it will also cause a small memory leak[citation needed]. The solution is to ensure the agent's reference count is 0 immediately after removing the agent[citation needed] (in other words, to make sure no references to the agent are kept for any amount of time after the agent has been removed). This is especially difficult in the case of units, and is usually dismissed.[citation needed]

This leak may have been inadvertently[weasel words] created by Blizzard while attempting to fix the common return bug in Patch 1.24[citation needed] (needs confirmation that it did not exist prior to this patch).

Personal tools