[racket-dev] weak boxes in a script

2011-03-16 Thread David Vanderson
I'm seeing a difference between when the value in a weak box is 
collected.  When I run the following interactively, the value is 
collected like I expect.  But it is not collected when running in a 
script, or in DrRacket.  This is v5.1 on Ubuntu x64, compiled from source.


Can someone explain the difference?

~$ racket
Welcome to Racket v5.1.
 (define b (make-weak-box 'not-used))
 (weak-box-value b)
'not-used
 (collect-garbage)
 (weak-box-value b)
#f


~$ cat weak-box.rkt
#lang racket

(define b (make-weak-box 'not-used))
(weak-box-value b)
(collect-garbage)
(weak-box-value b)

~$ racket weak-box.rkt
'not-used
'not-used

Thanks,
Dave
_
 For list-related administrative tasks:
 http://lists.racket-lang.org/listinfo/dev


Re: [racket-dev] weak boxes in a script

2011-03-16 Thread Carl Eastlund
David,

I believe you are seeing the difference between modules and the REPL.
At the REPL, each expression is compiled, run, and discarded.  This
yields the behavior you expect.  But a #lang form produces a module,
which is compiled and kept for the rest of the session.  Thus, even
after garbage collection, the compiled form of the first term still
exists:

(define b (make-weak-box 'not-used))

Thus there is a reference to the symbol not-used, and it is not
garbage collected.

Carl Eastlund

On Wed, Mar 16, 2011 at 5:09 PM, David Vanderson
david.vander...@gmail.com wrote:
 I'm seeing a difference between when the value in a weak box is collected.
  When I run the following interactively, the value is collected like I
 expect.  But it is not collected when running in a script, or in DrRacket.
  This is v5.1 on Ubuntu x64, compiled from source.

 Can someone explain the difference?

 ~$ racket
 Welcome to Racket v5.1.
 (define b (make-weak-box 'not-used))
 (weak-box-value b)
 'not-used
 (collect-garbage)
 (weak-box-value b)
 #f


 ~$ cat weak-box.rkt
 #lang racket

 (define b (make-weak-box 'not-used))
 (weak-box-value b)
 (collect-garbage)
 (weak-box-value b)

 ~$ racket weak-box.rkt
 'not-used
 'not-used

 Thanks,
 Dave

_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/dev


Re: [racket-dev] weak boxes in a script

2011-03-16 Thread David Vanderson

Thanks so much, that makes perfect sense.

On 03/16/2011 02:16 PM, Carl Eastlund wrote:

David,

I believe you are seeing the difference between modules and the REPL.
At the REPL, each expression is compiled, run, and discarded.  This
yields the behavior you expect.  But a #lang form produces a module,
which is compiled and kept for the rest of the session.  Thus, even
after garbage collection, the compiled form of the first term still
exists:

(define b (make-weak-box 'not-used))

Thus there is a reference to the symbol not-used, and it is not
garbage collected.

Carl Eastlund

On Wed, Mar 16, 2011 at 5:09 PM, David Vanderson
david.vander...@gmail.com  wrote:

I'm seeing a difference between when the value in a weak box is collected.
  When I run the following interactively, the value is collected like I
expect.  But it is not collected when running in a script, or in DrRacket.
  This is v5.1 on Ubuntu x64, compiled from source.

Can someone explain the difference?

~$ racket
Welcome to Racket v5.1.

(define b (make-weak-box 'not-used))
(weak-box-value b)

'not-used

(collect-garbage)
(weak-box-value b)

#f


~$ cat weak-box.rkt
#lang racket

(define b (make-weak-box 'not-used))
(weak-box-value b)
(collect-garbage)
(weak-box-value b)

~$ racket weak-box.rkt
'not-used
'not-used

Thanks,
Dave

_
 For list-related administrative tasks:
 http://lists.racket-lang.org/listinfo/dev