lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



On 1-Dec-06, at 10:40 PM, Diego Nehab wrote:

Hi,

I forget what is the standard solution to make Lua's GC
aware of the external cost of a "userdata" value. Sometimes
you have a userdata representing, say, an image. But the
image itself takes more room than the userdata because it
was allocated outside of Lua (sometimes you can't change
that). So Lua might not feel like collecting the userdata
eventhough it represents a lot of memory and is not
referenced anymore.

Can anyone refresh my memory?

__gc

__gc will only be executed when the garbage collector feels
like it. This decision is based on how much memory the userdata itself takes (a few bytes). However, this userdata might be just a boxed pointer, pointing to a big hunk of external
memory (say, a few megabytes).

I don't think that Lua makes its decision about which objects to delete based on their size. It does make a decision about how often to advance garbage collection based on its idea of how much memory is used, and then later on how much to advance sweeping based on its idea of how much memory has been freed.

Unaccounted for memory will cause the mark phase to be run too little and the sweep phase to be run too much. But as far as I can see, it won't change the order of which objects are collected.