Re: [racket-users] weak references and quoted values

2017-09-07 Thread Matthew Flatt
That's correct. Quoted values get GCed when code gets GCed, such as
when you run a module to completion in a namespace and don't retain the
namespace, or when a quoted value is sent to `eval` and not part of a
definition.

At Thu, 7 Sep 2017 17:31:26 -0700, Alexis King wrote:
> My understanding is that quoted values are effectively interned, so
> they’ll never be garbage collected as long as the code containing the
> quoted expression is loaded. Here’s a program that hints at this:
> 
>   (define (make-quoted-value)
> '(1 . 2))
> 
>   (eq? (make-quoted-value)
>(make-quoted-value))
>   ; => #t
> 
> So I think the answer is that quoted values are never garbage collected
> at all in normal, non-reflective uses. This is all just guessing,
> though; I’m sure Matthew could give a more authoritative explanation.
> 
> > On Sep 7, 2017, at 14:53, Stephen Chang  wrote:
> > 
> > Ran into some unexpected behavior today. Quoted values do not seem to
> > be garbage collected when there are only weak references. Is this
> > correct behavior?
> > 
> > 
> > Here's an example program:
> > 
> > #lang racket/base
> > 
> > (define key1 (list 1))
> > (define key2 '(1))
> > 
> > (define hash1 (make-weak-hash (list (cons key1 1
> > (define hash2 (make-weak-hash (list (cons key2 1
> > 
> > hash1
> > hash2
> > 
> > (set! key1 null)
> > (set! key2 null)
> > 
> > (collect-garbage) ; I tried a range of gc pressure here with no difference
> > 
> > hash1
> > hash2
> > 
> > 
> > I expected it to produce:
> > 
> > '#hash(((1) . 1))
> > '#hash(((1) . 1))
> > '#hash()
> > '#hash()
> > 
> > But instead got:
> > 
> > '#hash(((1) . 1))
> > '#hash(((1) . 1))
> > '#hash()
> > '#hash(((1) . 1))
> > 
> > 
> > Searching through the docs I found the following line [1] that maybe
> > explains the behavior (but I'm not sure)?
> > 
> > "Values produced by quote remain reachable when the quote expression
> > itself is reachable."
> > 
> > Is this saying that since the quoted value is reachable via the weak
> > reference, it is considered reachable?
> > 
> > [1] 
> http://docs.racket-lang.org/reference/eval-model.html?#%28part._gc-model%29
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] weak references and quoted values

2017-09-07 Thread Alexis King
My understanding is that quoted values are effectively interned, so
they’ll never be garbage collected as long as the code containing the
quoted expression is loaded. Here’s a program that hints at this:

  (define (make-quoted-value)
'(1 . 2))

  (eq? (make-quoted-value)
   (make-quoted-value))
  ; => #t

So I think the answer is that quoted values are never garbage collected
at all in normal, non-reflective uses. This is all just guessing,
though; I’m sure Matthew could give a more authoritative explanation.

> On Sep 7, 2017, at 14:53, Stephen Chang  wrote:
> 
> Ran into some unexpected behavior today. Quoted values do not seem to
> be garbage collected when there are only weak references. Is this
> correct behavior?
> 
> 
> Here's an example program:
> 
> #lang racket/base
> 
> (define key1 (list 1))
> (define key2 '(1))
> 
> (define hash1 (make-weak-hash (list (cons key1 1
> (define hash2 (make-weak-hash (list (cons key2 1
> 
> hash1
> hash2
> 
> (set! key1 null)
> (set! key2 null)
> 
> (collect-garbage) ; I tried a range of gc pressure here with no difference
> 
> hash1
> hash2
> 
> 
> I expected it to produce:
> 
> '#hash(((1) . 1))
> '#hash(((1) . 1))
> '#hash()
> '#hash()
> 
> But instead got:
> 
> '#hash(((1) . 1))
> '#hash(((1) . 1))
> '#hash()
> '#hash(((1) . 1))
> 
> 
> Searching through the docs I found the following line [1] that maybe
> explains the behavior (but I'm not sure)?
> 
> "Values produced by quote remain reachable when the quote expression
> itself is reachable."
> 
> Is this saying that since the quoted value is reachable via the weak
> reference, it is considered reachable?
> 
> [1] 
> http://docs.racket-lang.org/reference/eval-model.html?#%28part._gc-model%29

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] weak references and quoted values

2017-09-07 Thread Stephen Chang
Ran into some unexpected behavior today. Quoted values do not seem to
be garbage collected when there are only weak references. Is this
correct behavior?


Here's an example program:

#lang racket/base

(define key1 (list 1))
(define key2 '(1))

(define hash1 (make-weak-hash (list (cons key1 1
(define hash2 (make-weak-hash (list (cons key2 1

hash1
hash2

(set! key1 null)
(set! key2 null)

(collect-garbage) ; I tried a range of gc pressure here with no difference

hash1
hash2


I expected it to produce:

'#hash(((1) . 1))
'#hash(((1) . 1))
'#hash()
'#hash()

But instead got:

'#hash(((1) . 1))
'#hash(((1) . 1))
'#hash()
'#hash(((1) . 1))


Searching through the docs I found the following line [1] that maybe
explains the behavior (but I'm not sure)?

"Values produced by quote remain reachable when the quote expression
itself is reachable."

Is this saying that since the quoted value is reachable via the weak
reference, it is considered reachable?

[1] http://docs.racket-lang.org/reference/eval-model.html?#%28part._gc-model%29

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.