[prev in list] [next in list] [prev in thread] [next in thread]
List: racket-dev
Subject: [racket-dev] weak boxes in a script
From: david.vanderson () gmail ! com (David Vanderson)
Date: 2011-03-16 22:02:19
Message-ID: 4D81336B.9070808 () gmail ! com
[Download RAW message or body]
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.vanderson at 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
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic