lua-users home
lua-l archive

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

On Mon, Jul 16, 2018 at 4:02 AM, Pierre Chapuis <> wrote:
On Mon, Jul 16, 2018, at 03:00, Andrew Starks wrote:
What about calling collectgarnage(“collect”)?

In some system I did that in a global error handler (top-level pcall) to avoid problems. However that forces collection of all garbage, not a single object. I wouldn't do it after a for loop, for instance. Also that doesn't work (or isn't easy to write) if you call `return`.

Pierre Chapuis

I remain curious. Has this been tested and found too slow before?

I had a similar concern with file handles in a media playback system and I tried out two things that seemed to work. I did not do any extensive performance testing because everything we "fast enough" for what I was doing.

The first thing I did was run the GC after the section where I had opened it, using pcall to test for success.

The second thing I did was run the GC manually on every frame. This was simplest and worked great but is not practical for other applications.

I realize that making *sure* that you run GC in the event of failure can be tricky. You also have to make sure that you don't have any external references (or use week values). Given that this is the way in which Lua releases resources, and that the GC runs on its own anyway, it seems like this would be the path of least resistance and likely not *that* slow.

Andrew Starks