Registered: Apr, 2006
Re: Sources of Java Errors
Posted: May 19, 2008 5:07 PM
> You would only need one GC if it was done right. Instead
> of kicking off a global collection only when memory runs
> low, the GC could call finalize() on an object the moment
> it is no longer reachable. For example, when a function
> returns, all of the local variables would be collected
> right then and there (as long as they aren't contained in
> the return value).
> The problem is that bulk-mode GC is usually more efficient
> than per-object GC.
A while back I kept trying to explain that idea to one of the Alice ML folks who seemed to have a different take on it all, that the program author can use higher order hoodly-doodly to make their own RAII type stuff.
I appreciate all the talk of how letting things happen in libraries is great and all, but it can't be a truism for all features, otherwise there would be no core language ;-) and I sorta feel this RAII-GC thing such that should be in the language.
What I think roughly I don't really know what I'm talking about want is something like:
(a) a type to be of (multiply inherit / interface) which tells the GC that you have an RAII-finalize method.
(b) the GC keeps a stack of allocation references in parallel / inside the regular call stack (or whatever else is appropriate, e.g. if you are talking about closures on the heap). that stack is only for types from (a), not every possible type.
(c) the GC then runs the finalization, and configurably optionally the actual memory GC to boot, to close the resource when its scope exits.
I guess, alternatively, if your language let people register plug ins for when the VM hits certain points e.g. all stack popping, it actually could be a library.