HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Memory Leaks

02-23-2004, 06:32 AM#1
Telamon
So I've been reading a lot of past posts, and I've read that some triggers can cause memory leaks (specifically "Pick Every Unit in Region").

1. What triggers cause these leaks?
2. Are these leaks a problem?
3. Are these true memory leaks (like an unfreed malloc in C) or is the memory later reclaimed by a garbage collector (and thus not a problem).
4. If the warcraft 3 scripting language is garbage collected, does this cause lag in-game? My feeling is that it doesn't. I've noticed that some maps (particularly any that have AMAI installed) take a long time to exit from, and this is probably because of garbage collection.

I'm largely ignorant of the underlying technical details of the war3 scripting language implementation - if someone could point me to a brief overview of it, I have other questions as well and I think understanding how the script is executed would help me write better code.
02-23-2004, 09:30 AM#2
Cubasis
I read from your post that you know JASS, right?

Anyhow, to make this short. All created "handle" types that don't get destroyed after use....get leaked into memory untill the game ends, where WC3 gets rid of all the allocated memory.

So Memory Leaks == Long Exiting Times. And if the memory-leak is crazy, then it will cause in laggyness in-game.


These leaked handle types are most often ones that you get returned from another function. That's why you f.ex. leak a unit-group when you "Pick all units in (Get Units In Rect Matching Condition)". As ... it's calling the function "Get Units In Rect Matching Condition" ... and there it gets returned a Unit-Group, which...you lose out of sight (as you don't catch it into a variable). So it leaks.

The same is with locations, f.ex. "Center of Unit/Rect" each leak locations, and these are often worse/more-common than group leaks.


To avoid leaks, you have to catch every location, rect, unit-group, player-group, special-effect you create, and Remove/Destroy it after using it. Here are the functions needed:

call RemoveLocation( *location* )
call DestroyGroup( *group* )
call DestroyForce( *force* )
call DestroyEffect( *effect* )
call RemoveRect( *rect* )

You most often only have to worry about Locations and UnitGroups (Rects and Forces aren't used as much...and all widgets (units, items, destructibles) should not be "destroyed", as then you'd kill the unit, same with Players (which you ofcourse can't even do)).

Hope this helps, be sure to ask if you have more Q.

Cubasis
02-23-2004, 10:17 AM#3
Grater
2) They can be a problem. It depends on the magnitude of the leak... like if the leak is a part of an ultimate triggered spell, it probably wont be a problem. Then again if it's in a 0.5 periodic that does something for each player (ie count units of type footman for (picked player) ) then it will probably be a serious problem.

And all leaks are about 20 times more serious for users with 128MB computers than for 512MB.

3&4) [Unit Group, Location etc] Leaks are garbage collected when the game ends.
Theres also speculation that other things that leak but cannot be destroyed by the triggerer are automatically GC'd during game-time.
For example if you keep spawning units, and they keep dying, the memory usage keeps increasing despite the number of units alive being constant.
But the memory increase rate drops as more and more units are created, suggesting that memory is being recycled automatically. I think that WC3 allocates fresh memory up to a certain threshold, then tries to recycle memory, but some memory is unreclaimable (ie due to fragmentation) so it needs to keep allocating some new memory. But theres nothing much you can do to influence this recycling behaivour.

The most important thing is to clean up the stuff Cubasis mentioned.