Re: Compile Time Garbage Collection impossible?

Pascal Bourguignon <pjb@informatimago.com>
25 Sep 2006 01:12:34 -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? pjb@informatimago.com (Pascal Bourguignon) (2006-09-25)
Re: Compile Time Garbage Collection impossible? dido@imperium.ph (Rafael 'Dido' Sevilla) (2006-09-25)
Re: Compile Time Garbage Collection impossible? kym@ukato.freeshell.org (russell kym horsell) (2006-09-25)
Re: Compile Time Garbage Collection impossible? paul.biggar@gmail.com (Paul Biggar) (2006-09-25)
Re: Compile Time Garbage Collection impossible? firefly@diku.dk (Peter \Firefly\Lund) (2006-09-25)
Re: Compile Time Garbage Collection impossible? gneuner2@comcast.net (George Neuner) (2006-09-25)
Re: Compile Time Garbage Collection impossible? liekweg@ipd.info.uni-karlsruhe.de (Florian Liekweg) (2006-09-25)
[12 later articles]
| List of all articles for this month |
From: Pascal Bourguignon <pjb@informatimago.com>
Newsgroups: comp.compilers
Date: 25 Sep 2006 01:12:34 -0400
Organization: Informatimago
References: 06-09-119
Keywords: GC
Posted-Date: 25 Sep 2006 01:12:34 EDT

the.real.doctor.zoidberg@gmail.com writes:


> Why isn't Compile-Time-Garbage-Collection feasible? Consider a Java
> compiler which produces assembly code for a specific target instead of
> Java's bytecode cenario. The objective is to use Java without the need
> for a GC or VM.
>
> I'm asking why it isn't possible because otherwise there would be at
> least one compiler to use that technique, instead of having to run a
> GC in the VM.
>
> 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?
>
> Thank you for any insight on this matter.


Consider this example:


(defparameter *data* '())


(defun main ()
    (loop
          :for cmd = (loop
                                      :with options = '(set query remove quit)
                                      :for cmd = (progn
                                                                (format *query-io* "Menu: ~{~% ~A~}~%Cmd? "
                                                                                options)
                                                                (read *query-io*))
                                      :until (member cmd options)
                                      :finally (return cmd))
          :do (case cmd
                      ((quit) (return-from main))
                      ((set) (let ((key (progn (format *query-io* "Key? ")
                                                                                  (read *query-io*)))
                                                      (value (progn (format *query-io* "Value? ")
                                                                                  (read *query-io*))))
                                              (setf (getf *data* key) value)))
                      ((query) (let ((key (progn (format *query-io* "Key? ")
                                                                                  (read *query-io*))))
                                              (format t "Key: ~A~%Value: ~A~2%"
                                                              key (getf *data* key))))
                      ((remove) (let ((key (progn (format *query-io* "Key? ")
                                                                                  (read *query-io*))))
                                              (remf *data* key))))))




You cannot know what elements of the list *data* you can garbage
collect at any time, because they came from user input and user input
directs when they are not needed anymore.




> [Local objects are usually stack allocated and freed at end of scope.
> You need GC when you do dynamic allocation, and chain stuff into lists
> and trees of data structures. -John]


Indeed.


--
__Pascal Bourguignon__ http://www.informatimago.com/


Post a followup to this message

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