Memory Leaks
From WarCraft3
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:
- Location - RemoveLocation
- Group - DestroyGroup
- Force - DestroyForce
- Lightning - DestroyLightning
- Texttag - DestroyTextTag
- Effect - DestroyEffect or Special Effect - Destroy Special Effect
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
| This section contains instructions, advice, or how-to content. The purpose of Wikipedia is to present facts, not to train. Please help improve this article either by rewriting the how-to content or by moving it to Wikiversity or Wikibooks. |
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
| This section contains instructions, advice, or how-to content. The purpose of Wikipedia is to present facts, not to train. Please help improve this article either by rewriting the how-to content or by moving it to Wikiversity or Wikibooks. |
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
| This section contains instructions, advice, or how-to content. The purpose of Wikipedia is to present facts, not to train. Please help improve this article either by rewriting the how-to content or by moving it to Wikiversity or Wikibooks. |
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).