lua-users home
lua-l archive

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

On Jun 13, 2016, at 4:04 PM, Sean Conner <> wrote:
>  I don't think that will give you any valid information.  GC happens
> asynchronously from the program (well, it can be viewed that way).  For
> instance:
> 	o = new_object() -- something with a metatable and a __gc method
> 	o = nil
>  The __gc() method isn't called when o is set to nil.  It just dereferences
> the object from it's "container" (so to speak).  At some point in the
> future, when the GC does run, the GC will notice that there are no more
> references to the object, and then call its __gc() method.  So obtaining a
> stack trace when __gc is called isn't really a valid thing to do generally. 

Oh, good point! I’m logging the stack trace in realloc, and since Lua frees memory by reallocing the block to zero bytes it was logging there too. I’ll just skip the trace if size is zero. As you say, knowing where it was freed isn’t really useful.

Many thanks!