RE: Compile Time Garbage Collection impossible?

"Daniele Terdina" <daniele@infoconex.com>
25 Sep 2006 01:12:53 -0400

          From comp.compilers

Related articles
Compile Time Garbage Collection impossible? the.real.doctor.zoidberg@gmail.com (2006-09-22)
RE: Compile Time Garbage Collection impossible? qtj-query@shaw.ca (Quinn Tyler Jackson) (2006-09-25)
RE: Compile Time Garbage Collection impossible? daniele@infoconex.com (Daniele Terdina) (2006-09-25)
| List of all articles for this month |

From: "Daniele Terdina" <daniele@infoconex.com>
Newsgroups: comp.compilers
Date: 25 Sep 2006 01:12:53 -0400
Organization: Compilers Central
References: 06-09-119
Keywords: GC
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.


Example:


function Foo()
{
ref = new Object;
Bar(ref);
}


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.


Daniele



Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.