View Single Post
08/09/14, 05:11 PM   #12
zgrssd
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 280
Originally Posted by mctaylor View Post
I'm assuming even well-behaved add-ons aren't expected to listen and effectively reaction to this event?

With Lua's garbage collection, can you free much memory usage from within an add-on? Free up a few tables by setting them to nil? Set any textures to nil or unload otherwise free them?
The best you can do for memory management is to use weak table references where appropirate (cachign scenarios):
http://www.lua.org/pil/17.html

That way the GC can decide to throw it out when it needs memory, but it stays around if no collection is neesesary.
And generally the GC should have tried to collect everything possible before it runs into a OOM exception.
The most reliable way to use a weak reference is to assign it's value to a local variable.
If the item was already collected, you get nil. If not, you now have a strong reference (for the duration of your code).

I used a weak reference table for the cache in LibConstantMapper. If the GC needs the memory, it can collect it any time. If not, it keeps the calls up to speed.
  Reply With Quote