Table garbage collection

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Table garbage collection

aryajur
Hi,
       I am trying to debug a situation where I have a table A referred to in a weak value table B and also in another data structure C. I then delete A from the data structure C. I then run collectgarbage(). Now I am expecting table A to disappear from table B but it is still there. 
       So it means that A is also somewhere else. Is there a way to see which references are preventing A from being garbage collected?

Thanks,
Milind 
Reply | Threaded
Open this post in threaded view
|

Re: Table garbage collection

Robert Burke
Hello,

I was working on something similar to a thing that could be used to
answer this question, so I made it into a thing that could be used to
answer this question. See here:
https://gist.github.com/sharpobject/8b3b1185a6351c972b02346093c42088

In your case, you can call paths.get_paths(function() return
my_weak_table[my_key] end) to get a list of paths from a few starting
points. It takes a function like this to avoid creating extra
references to the thing, which would then be found by get_paths,
adding some noise to the output.

On Tue, Jul 14, 2020 at 11:01 AM Milind Gupta <[hidden email]> wrote:
>
> Hi,
>        I am trying to debug a situation where I have a table A referred to in a weak value table B and also in another data structure C. I then delete A from the data structure C. I then run collectgarbage(). Now I am expecting table A to disappear from table B but it is still there.
>        So it means that A is also somewhere else. Is there a way to see which references are preventing A from being garbage collected?
>
> Thanks,
> Milind
Reply | Threaded
Open this post in threaded view
|

Re: Table garbage collection

aryajur
Thank you very much! This was very helpful.

Best Regards,
Milind

On Tue, Jul 14, 2020 at 12:47 AM Robert Burke <[hidden email]> wrote:
Hello,

I was working on something similar to a thing that could be used to
answer this question, so I made it into a thing that could be used to
answer this question. See here:
https://gist.github.com/sharpobject/8b3b1185a6351c972b02346093c42088

In your case, you can call paths.get_paths(function() return
my_weak_table[my_key] end) to get a list of paths from a few starting
points. It takes a function like this to avoid creating extra
references to the thing, which would then be found by get_paths,
adding some noise to the output.

On Tue, Jul 14, 2020 at 11:01 AM Milind Gupta <[hidden email]> wrote:
>
> Hi,
>        I am trying to debug a situation where I have a table A referred to in a weak value table B and also in another data structure C. I then delete A from the data structure C. I then run collectgarbage(). Now I am expecting table A to disappear from table B but it is still there.
>        So it means that A is also somewhere else. Is there a way to see which references are preventing A from being garbage collected?
>
> Thanks,
> Milind