[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: GC and memory management
- From: roberto@... (Roberto Ierusalimschy)
- Date: Fri, 30 Jun 2006 11:34:41 -0300
> Also, something I don't really understand: If there isn't enough memory, my
> allocator function can detect it and return NULL. Then the interpreter raise
> an error and the execution breaks softly. But in that case why doesn't the
> interpreter try to perform a GC cycle, then try to allocate memory again?
> Most of the time a part of memory may be safely freed and this allocation
> shouldn't break the program.
> Would it be safe to manualy call the GC in the allocator function in case of
> failure?
Unfortunately no, with the current structure of Lua. Several objects
(e.g., tables) need several memory blocks. If a memory allocation fails
in an intermediate block and you call the GC, previously allocated blocks
would be collected. (The object only goes to the root set when it is
assigned to a variable, which only happens after it has been completely
created.)
-- Roberto