View Single Post
08/18/14, 08:33 AM   #14
TotterTates
Join Date: Apr 2014
Posts: 1
Originally Posted by zgrssd View Post
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.
I can build a computer and customize pieces of hardware like nobody's business, but when it comes to writing code I'm completely lost. Could I trouble you to assist with adding these tables to my files?
  Reply With Quote