[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Memory leak?
- From: "Mark Meijer" <meijer78@...>
- Date: Wed, 30 Jan 2008 19:29:26 +0100
On 30/01/2008, firstname.lastname@example.org <email@example.com> wrote:
> I'm guessing you saw in the reply that the GC can collect the keys =). So the
> loss is only minor - it's only the 28 (or 32, depending on kludge factor) bytes
> for a Node. The key can still be collected, just not the node.
Yeah :) Thanks.
> Yes, that would work. I can't see it being implemented though for the number of
> bugs it could introduce in seemingly good code. Just think, a function that'd
> break any pairs() loop it's inside of, no matter how nested the call to this
> function is. And not just break the ordering, but make the loop throw an error -
> something a normal loop would never do.
Your point is well taken, if only to dismiss the suggestion I did that
at least collectgarbage("collect") should clean up the remaining nodes
(in addition to the full collection cycle). I.e. perhaps it shouldn't,
for the reason you mention.
But I don't think anyone is currently calling collectgarbage("keys")
anywhere, much less in a loop involving next(), since "keys" is not a
valid argument to collectgarbage :) ...(or whatever would be a
suitable name for it, if not "keys").
Though I admittedly don't know the result of calling collectgarbage
with an invalid argument, it's most likely either strictly invalid and
returns nothing (or error), or the behaviour is "undefined". Either
way, I'd have to argue that it is perfectly safe to add this extra
option without breaking any existing code.
If that still makes people uncomfortable, then it could just as well
be made into a separate function with a different name. And if that
still makes people uncomfortable, then - dangnabbit :P - add it to the
Lua C API or something, lol...
Even if nobody will ever need it for all eternity until the end of
human-kind, one day an alien civilization is going to dig up Lua from
our remains and say "jeesh, it held on to memory even when no longer
needed, and there was no way to reclaim it?"
Heheh... Ok jokes aside, the principle being: It is my humble opinion
that there should be a way to reclaim those nodes without having to
dig into Lua internals and modify and recompile it. :)