[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: forcing userdata to be gc'd?
- From: John Dunn <John.Dunn@...>
- Date: Wed, 29 Mar 2017 20:51:53 +0000
If I have a userdata that wraps a limited system resource ( ie file handle, socket, large block of C memory, etc ), is there a way to make the userdata more likely to be garbage collected? For example, if I have a userdata wrapped socket with the following code
sock = nil
for i = 1,1000 do
sock = socket.new() -- create new userdata wrapping a socket
end
1000 sockets will likely be created before any of the non-referenced userdatas are collected. I can solve this with require careful script coding ( having a sock:close() call that has to be called when you are done with the socket, calling collectgarbage(), etc ) but I'd like a solution that is more robust than that. It seems like a way to tag something to always be garbage collected as soon as there are no longer any references might work.
John