|Compile Time Garbage Collection impossible? email@example.com (2006-09-22)|
|RE: Compile Time Garbage Collection impossible? firstname.lastname@example.org (Quinn Tyler Jackson) (2006-09-25)|
|RE: Compile Time Garbage Collection impossible? email@example.com (Daniele Terdina) (2006-09-25)|
|From:||"Daniele Terdina" <firstname.lastname@example.org>|
|Date:||25 Sep 2006 01:12:53 -0400|
|Posted-Date:||25 Sep 2006 01:12:53 EDT|
> Why isn't Compile-Time-Garbage-Collection feasible? Consider a Java
> When a program is compiled, the compiler has to transverse all its
> code to ensure type safety (for safe languages), so what would be the
> problem in "freeing" objects after their scope, or even better, after
> the last reference in their scope?
Except for trivial cases, the compiler can't infer objects' lifetimes.
ref = new Object;
Reference ref goes out of scope at the end of Foo(), but the compiler can't
decide whether to delete the referenced object or not at the end of Foo()
without knowing whether Bar created other references to it or not, and in
general this can't be proved (just think of a function Bar() that creates a
new global reference to the object only if the user is pressing the space
bar while Bar() executes).
So in the general case you need runtime mechanisms like reference counting
or garbage collection.
Return to the
Search the comp.compilers archives again.