Memory, GC, World of Warcraft and You!

#1 - Feb. 9, 2007, 2:36 p.m.
Blizzard Post
I've seen lots of people who are seeing MORE freezes with 2.0.1
Unfortunately, this is a combination of a number of factors, but the resolution is already slated for 2.1.0! Let me first explain the components that are involved in causing this problem:

* Max AddOn Memory - This is the little box at the top right of your addons screen which tells the system how much memory you can use for all addons. This was originally put in to have a "cap" on the memory usage (which wasn't all that easy to monitor) and to prevent extremely large addons from using a huge amount of memory and causing problems. It was originally set to 32, but was increased to 48 at some point during the patch cycle. Most people have this value set to 48.

* Pause value - Remember before, when I talked about the "threshold" that started garbage collection in Lua 5.0? It waited until the system was at 1.5 times the last memory value before starting a garbage collection cycle, stopping the world. In Lua 5.1, the threshold value exists in the form of the "pause" attribute. This allows the system to run without ANY garbage collection for a period of time, only starting the incremental collector at a certain threshold. This is just in place to prevent the system from _always_ running, since while it’s awfully cheap due to the small steps it takes, it’s still not free.

In the default WoW installation, the max memory is set to 48, and the pause value is set to 200% (2 times) the last memory measurement. This means if a user logs into the system with 20 MiB of memory being used by addons, the garbage collector will start up at 40 MiB and then start taking its small steps to free memory. This is where the problem occurs.

If the user has more than 1/2 their max addon memory value (in our case, if they have 25 MiB initial memory) then garbage collection won't start until 50 MiB.. which we won't ever reach due to our max addon memory. When this happens, the system "panics" and runs a full garbage collection to see if it can free memory. This is a good thing, since otherwise your game would crash =). Unfortunately, when the system panics like this, no garbage has been freed (remember the collector hasn't been started yet) so it has QUITE a lot of memory to go through, and even more to free. This can cause a very significant pause of your game under certain circumstances.

Okay, so what's being done to fix it?
In the 2.1.0 patch, slouken has reworked a lot of the memory system to make it more efficient, and changed the way memory is being allocated in a way that will drop the amount of memory being used by the default UI, and possibly by addons as well. Here are the net changed to the memory system in 2.1.0:

* Script memory can now be tracked on a per-addon basics. You can call the UpdateAddOnMemoryUse() function to calculate the system memory, and then call GetAddOnMemoryUse(index or "name") to get the addon's memory in KiB.
* The memory system has been optimized and garbage collection has been tuned.
* There is no longer a "Max Addon Memory" setting available, it should no longer be needed.
* Players will be able to see the top three addons in memory usage, within the default UI. Custom addons will be able to display more detailed information about addon memory usage.
#11 - Feb. 9, 2007, 9:29 p.m.
Blizzard Post
If you want to get a sneak peek at the new settings in 2.1.0, you can do this:
/script collectgarbage("setpause", 110)

Enjoy!

Edit: Great post by the way! Thanks Cladhaire!
#19 - Feb. 10, 2007, 3:43 a.m.
Blizzard Post
Just stick in a macro and run it every time you log in. Combining that with setting your memory limit to 0 is very close to what will be the default in 2.1.0.