lua-users home
lua-l archive

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

Why would you need a __gc metamethod for tables?

It's about remote invocation. My table is a proxy for an object on another computer, it delegates some actual computations to that remote computer. To properly perform these computations, the remote computer needs to retain some (remote) resources. So when my local proxy table is collected, I need to let the remote computer know that I don't need these resources anymore, so that they can in turn be collected. Not sure how clear I am...

There are heavy dirty solutions, like registering the proxy in a weak table, regularly checking what's been removed from the weak table, and transmit to the remote computer a list of collected proxies names, but I can't believe there isn't a cleaner way!