[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Can userdate have references to lua objects?
- From: RLake@...
- Date: Mon, 12 May 2003 15:22:17 -0500
>> A memory leak is where allocated memory(2) is not freed although it is
>> never used again.
> This is a funny definition. If I do "a = {}" and never use "a" again, I
> have a memory leak... So memory leaks are non-computable.
That's true. Not all properties have to be computable. :)
The point, I think, is that a garbage collector always makes a conservative
estimate of "live"-ness. It cannot a priori tell which objects a program is
going to reference in the future. However, it *may be able* to make a
better estimate than simply doing reachability analysis. For example,
syntactic analysis could easily reveal circumstances in which a local is
never referred to again. It wouldn't catch all of them, but it would
improve the estimate. Rather than insert explicit code to clear the stack
slot, the compiler could simply leave a record for the garbage collector.
This would be entirely legitimate.
Now it is true that I could iterate over a weak table and thereby get at
weak values for which there are no other pointers provided I do so before
garbage collection runs. But garbage collection could run at any time, so
such objects are not reliably reachable, and it is impossible to reason
about such objects without knowing anything about the semantics of the
garbage collection. So I probably should not iterate over a weak table, or
if I do I should do so bearing in mind that elements may or may not be
reachable. And if I don't iterate over the weak table, the corresponding
strong objects truly are unreachable (unless they are reachable through
some other reference.)
In either case, there is no reasonable expectation that the objects are
live, and the garbage collector should delete them.
For it not to do so does not make the garbage collector invalid, nor does
it make the language less lovely. It just means that one particularly
useful programming pattern (annotation or, if you like, "side-band" data)
is not possible. I guess how much priority is placed on the issue depends
on how much one cares about that programming pattern.
R.