Dr Super Good
Spell Reviewer
- Joined
- Jan 18, 2005
- Messages
- 27,258
Recently a lot of people have been making claims about leaks giving theories and sometimes even evidence to support them. However are they really true?
RemoveUnit() leak
Recently a bunch of people claimed that the native to remove a unit was leaking. They said that killing a unit does not leak and should be used instead. I believed this and supported this as their argument sounded plausable.
That was until I actually bothered to try it out...
I tested all kinds of unit removal I could think of...
RemoveUnit
KillUnit
UnitApplyTimedLife
As killing is not usually instant at removal, I hid the units, made them explode and set their explode graphics to none.
Do they leak leak handle IDs?
In a map with no modified object data I started a timer at map initialization with 1 timeout which ran a function. This function created a footman unit at map origan belonging to player 0 which it then immediatly removed via one of the methods. The map run without any other trigger activity and the handle ID of spawned footman unit was tested before it got removed via a simple line of code inserted into the function. The handle ID displayed remained constant for all itterations. The same was repeated with the explode kill method and timed life method both yielding the same result.
RemoveUnit, killing a unit and letting a unit expire all do not leak handle IDs
Does RemoveUnit() leak memory?
The same setup above was used, this time the timer was reduced to 0.001 seconds (about 1000 itterations a second) and code inserted to stop at 100000 itterations. The map was tested with WC3 in window mode with task manager used to monitor the various working set and commit sizes of WC3 (what is loaded into active memory) to detect for memory leaks as the code runs. All 3 types of unit removal were tested.
The results showed a memory leak of some form that was persistant between all 3 types of removal even down to approximatly the same quantity of data leaking.
This means that creating units or the global dealocation of units must leak no mater how it is done with triggers. After creating 100000 units at 1000 units a second only a couple of MB leaked meaning the leaked can be ignored mostly. Creating 100000 unique strings leaked more than 100000 units. The crash related to the unit leak has not been investigated.
Interesting Note
Handle IDs get recycled perodically (about every 5 mili seconds or 200 times a second from a rough test) rather than as they become freed.
RemoveUnit() leak
Recently a bunch of people claimed that the native to remove a unit was leaking. They said that killing a unit does not leak and should be used instead. I believed this and supported this as their argument sounded plausable.
That was until I actually bothered to try it out...
I tested all kinds of unit removal I could think of...
RemoveUnit
KillUnit
UnitApplyTimedLife
As killing is not usually instant at removal, I hid the units, made them explode and set their explode graphics to none.
Do they leak leak handle IDs?
In a map with no modified object data I started a timer at map initialization with 1 timeout which ran a function. This function created a footman unit at map origan belonging to player 0 which it then immediatly removed via one of the methods. The map run without any other trigger activity and the handle ID of spawned footman unit was tested before it got removed via a simple line of code inserted into the function. The handle ID displayed remained constant for all itterations. The same was repeated with the explode kill method and timed life method both yielding the same result.
RemoveUnit, killing a unit and letting a unit expire all do not leak handle IDs
Does RemoveUnit() leak memory?
The same setup above was used, this time the timer was reduced to 0.001 seconds (about 1000 itterations a second) and code inserted to stop at 100000 itterations. The map was tested with WC3 in window mode with task manager used to monitor the various working set and commit sizes of WC3 (what is loaded into active memory) to detect for memory leaks as the code runs. All 3 types of unit removal were tested.
The results showed a memory leak of some form that was persistant between all 3 types of removal even down to approximatly the same quantity of data leaking.
This means that creating units or the global dealocation of units must leak no mater how it is done with triggers. After creating 100000 units at 1000 units a second only a couple of MB leaked meaning the leaked can be ignored mostly. Creating 100000 unique strings leaked more than 100000 units. The crash related to the unit leak has not been investigated.
Interesting Note
Handle IDs get recycled perodically (about every 5 mili seconds or 200 times a second from a rough test) rather than as they become freed.
Last edited: