[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: How to write the __gc metamethod of referenced userdata?
- From: Xavier Wang <weasley.wx@...>
- Date: Wed, 22 Jun 2011 16:41:32 +0800
hi all, I have meet another problem :(
say, I have two userdata, A and B, and A has reference against B, you can treat A as B's parent. I want:
- if A is collecting, collect the B, either.
- don't collect B if B is referenced by A.
I know I can make a table in registry to record the dependence of A and B, but it wastes memory, and you can't collect the memory in a table has dead-key, even it's a weak table! So is there any other way to tell lua this dependence?
note that I need use the env table of A and B, so I can't record it in the env table.