<div dir="ltr">That is also what I meant by code (well, I was speaking generally about all bytecode). <div><br></div><div>The point I'm making is that this is not a limitation of our runtime system, it is just because you are imagining there are still references to that bytecode.</div>
<div><br></div><div>In the specific instance you mention below, the namespace holding onto that module could become garbage. This happens in DrRacket a lot, for example.</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">
On Thu, Feb 14, 2013 at 7:45 AM, Jay McCarthy <span dir="ltr"><<a href="mailto:jay.mccarthy@gmail.com" target="_blank">jay.mccarthy@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
When I say "code", I mean module top-level binding byte-code. There's<br>
no way for Racket to remove<br>
<br>
(define (f x) (lambda (y) (printf "Gigantic string: ~a" (+ x y))))<br>
<br>
at the top-level. The byte-code will always contain the gigantic<br>
string. If you ever call f and get back something, that closure could<br>
be collected, but not the source that generated it.<br>
<span class="HOEnZb"><font color="#888888"><br>
Jay<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
On Thu, Feb 14, 2013 at 6:37 AM, Robby Findler<br>
<<a href="mailto:robby@eecs.northwestern.edu">robby@eecs.northwestern.edu</a>> wrote:<br>
> I'm pretty sure code is collected in (regular) Racket. Small numbers aren't<br>
> collected, true, but they also don't really take any space. Big numbers are<br>
> collected, too. (I'm not sure about interned symbols.)<br>
><br>
> Robby<br>
><br>
><br>
> On Thu, Feb 14, 2013 at 7:26 AM, Jay McCarthy <<a href="mailto:jay.mccarthy@gmail.com">jay.mccarthy@gmail.com</a>><br>
> wrote:<br>
>><br>
>> In the Web server language, all anonymous functions are turned into<br>
>> top-level structures masquerading as functions where the fields are<br>
>> their free variables. For instance:<br>
>><br>
>> (define (f x) (lambda (y) (+ x y))<br>
>><br>
>> becomes, roughly,<br>
>><br>
>> (struct a-lambda42 (x)<br>
>> #:property prop:procedure<br>
>> (lambda (the-structure y)<br>
>> (define x (a-lambda42-x the-structure))<br>
>> (+ x y)))<br>
>> (define (f x) (make-a-lambda42 x))<br>
>><br>
>> In your program, the expression<br>
>><br>
>> (web-cell-shadow wc-anonymous (λ (x) 'more-distinctive-text))<br>
>><br>
>> becomes<br>
>><br>
>> (struct a-lambda43 () #:property prop:procedure (lambda (s x)<br>
>> 'more-distinctive-text))<br>
>> (web-cell-shadow wc-anonymous (make-a-lambda43))<br>
>><br>
>> Notice that the anonymous function has no fields because there are no<br>
>> free variables. The distinctive text is not shown anywhere in the URL<br>
>> because it is part of the code, not part of the data, of the closure.<br>
>><br>
>> If you change the program slightly to<br>
>><br>
>> (web-cell-shadow wc-anonymous<br>
>> (let () (define y 'more-distinctive-text)<br>
>> (λ (x) y)))<br>
>><br>
>> then y is a free variable, so when you look at the URL:<br>
>><br>
>><br>
>> <a href="http://localhost:8000/;((%22c%22%20.%20%220((3)%204%20(((lib%20%5C%22web-server%2Flang%2Fabort-resume.rkt%5C%22)%20.%20%5C%22lifted.6%5C%22)%20((lib%20%5C%22web-server%2Flang%2Fweb-cells.rkt%5C%22)%20.%20deserialize-info:frame-v0)%20(%23%5C%22%2Ftmp%2Ft.rkt%5C%22%20.%20%5C%22lifted.1683%5C%22)%20(2%20.%20%5C%22lifted.1991%5C%22))%200%20()%20()%20(0%20(1%20(h%20-%20()%20(lifted.1485-0%20.%20this-is-a-song-about-Japan)%20(lifted.1521-1%202%20(b!%20.%20more-distinctive-text))))%20(c%20(v!%20(3)%20%23f%20%23f))))%22))" target="_blank">http://localhost:8000/;((%22c%22%20.%20%220((3)%204%20(((lib%20%5C%22web-server%2Flang%2Fabort-resume.rkt%5C%22)%20.%20%5C%22lifted.6%5C%22)%20((lib%20%5C%22web-server%2Flang%2Fweb-cells.rkt%5C%22)%20.%20deserialize-info:frame-v0)%20(%23%5C%22%2Ftmp%2Ft.rkt%5C%22%20.%20%5C%22lifted.1683%5C%22)%20(2%20.%20%5C%22lifted.1991%5C%22))%200%20()%20()%20(0%20(1%20(h%20-%20()%20(lifted.1485-0%20.%20this-is-a-song-about-Japan)%20(lifted.1521-1%202%20(b!%20.%20more-distinctive-text))))%20(c%20(v!%20(3)%20%23f%20%23f))))%22))</a><br>
>><br>
>> You see the distinctive text.<br>
>><br>
>> As far as GC goes, code is not generally collected in Racket anyways.<br>
>> Any data that is an intrinsic part of the program text (such as<br>
>> literal symbols and numbers) will always be around in your program<br>
>> whether you use #lang web-server or not.<br>
>><br>
>> Jay<br>
>><br>
>><br>
>> On Wed, Feb 13, 2013 at 8:34 PM, Galler <<a href="mailto:lzgaller@optonline.net">lzgaller@optonline.net</a>> wrote:<br>
>> > Good evening,<br>
>> ><br>
>> > I've been investigating lang web-server, performance and garbage<br>
>> > collection<br>
>> ><br>
>> > I have a question regarding anonymous functions and web cells<br>
>> ><br>
>> > Examples below require:<br>
>> ><br>
>> > #lang web-server<br>
>> > (require racket/serialize<br>
>> > web-server/lang/web-cells)<br>
>> ><br>
>> ><br>
>> > Constants appear serializable by their value being explicitly written<br>
>> > out<br>
>> ><br>
>> ><br>
>> > For example,<br>
>> ><br>
>> > (serialize 'this-is-a-song-about-japan)<br>
>> ><br>
>> > ;-> '((3) 0 () 0 () () this-is-a-song-about-japan)<br>
>> ><br>
>> ><br>
>> > Whereas anonymous functions appear serializable by the mechanism of<br>
>> > being<br>
>> > "lifted" (i.e. reified) to a module level binding<br>
>> ><br>
>> > For example<br>
>> ><br>
>> > (serialize (λ (x) x))<br>
>> ><br>
>> > ;-> '((3) 1 (('anonymous-module . "lifted.1386")) 0 () () (0))<br>
>> ><br>
>> ><br>
>> > Moving the discussion to web-cells<br>
>> ><br>
>> > (define wc-constant (make-web-cell #f))<br>
>> ><br>
>> > (define wc-anonymous (make-web-cell #f))<br>
>> ><br>
>> ><br>
>> > (web-cell-shadow wc-constant 'this-is-a-song-about-Japan)<br>
>> ><br>
>> > (web-cell-shadow wc-anonymous (λ (x) x))<br>
>> ><br>
>> > (printf " wc-constant: ~A\n wc-anonymous: ~A\n"<br>
>> > (serialize wc-1)<br>
>> > (serialize wc-2))<br>
>> ><br>
>> > returns<br>
>> ><br>
>> > wc-constant: ((3) 1 (((lib web-server/lang/web-cells.rkt) .<br>
>> > deserialize-info:primitive-wc-v0)) 0 () () (0 lifted.1534-0))<br>
>> ><br>
>> > wc-anonymous: ((3) 1 (((lib web-server/lang/web-cells.rkt) .<br>
>> > deserialize-info:primitive-wc-v0)) 0 () () (0 lifted.1570-1))<br>
>> ><br>
>> ><br>
>> ><br>
>> > While now both values are 'lifted' (i.e. reified), a close examination<br>
>> > of<br>
>> > the URL-string sent back to a client after send/suspend/dispatch<br>
>> ><br>
>> > reveals that, with respect to the constant, lifted.1534 appears to be<br>
>> > explicitly represented, elsewhere in the string as an associative pair<br>
>> > i.e.<br>
>> > (lifted.1534 this-is-a-song-about-Japan)<br>
>> ><br>
>> > whereas for the anonymous function, its not clear that its reference,<br>
>> > lifted.1570 is explicitly represented<br>
>> ><br>
>> > Which leads me to wonder about whether the reference to the anonymous<br>
>> > function, lifted.1570, is being maintained on the server,<br>
>> ><br>
>> > And if so, how is it being garbage collected, as its impossible to ever<br>
>> > determine that it is unreachable.<br>
>> ><br>
>> > I will also point out that prior to a year ago, anonymous functions<br>
>> > failed<br>
>> > the serializability predicate. (serializable? anon-func) -> #f. I can<br>
>> > pull<br>
>> > out the correspondence/background related to that if desirable.<br>
>> ><br>
>> > I apologize if I'm just misreading the data.<br>
>> ><br>
>> > Here's the complete example,with a stateless web server. Note that when<br>
>> > you<br>
>> > inspect the url-string**for the datum this-is-a-song-about-Japan, its<br>
>> > there,<br>
>> > but when looking for the datum more-distinctive-text, its not present in<br>
>> > the<br>
>> > url-string.<br>
>> ><br>
>> > **right click on the link, then copy/paste, or click the 'click-me' link<br>
>> > and<br>
>> > copy/paste the URL from the address bar)<br>
>> ><br>
>> > Thanks very much.<br>
>> ><br>
>> ><br>
>> > Thanks again.<br>
>> ><br>
>> ><br>
>> ><br>
>> > #lang web-server<br>
>> ><br>
>> > (require web-server/servlet-env)<br>
>> ><br>
>> > (define wc-constant (make-web-cell #f))<br>
>> ><br>
>> > (define wc-anonymous (make-web-cell #f))<br>
>> ><br>
>> ><br>
>> > (web-cell-shadow wc-constant 'this-is-a-song-about-Japan)<br>
>> ><br>
>> > (web-cell-shadow wc-anonymous (λ (x) 'more-distinctive-text))<br>
>> ><br>
>> > (define (start request)<br>
>> > (letrec ((response-generator (λ (make-url)<br>
>> > (response/xexpr `(html (head)<br>
>> > (body (a ((href<br>
>> > ,(format "~A" (make-url receive-request)))) "click me"))))))<br>
>> > (receive-request (λ (request)<br>
>> > (response/xexpr `(html (head)<br>
>> > (body "Thank you.<br>
>> > We<br>
>> > are done."))))))<br>
>> > (send/suspend/dispatch response-generator)))<br>
>> ><br>
>> > (serve/servlet start<br>
>> > #:stateless? #t<br>
>> > #:launch-browser? #t<br>
>> > #:connection-close? #t<br>
>> > #:quit? #f<br>
>> > #:listen-ip #f<br>
>> > #:port 8000<br>
>> > #:servlet-path "/")<br>
>> ><br>
>> ><br>
>> ><br>
>> > Thanks much.<br>
>> ><br>
>> > Zack<br>
>><br>
>><br>
>><br>
>> --<br>
>> Jay McCarthy <<a href="mailto:jay@cs.byu.edu">jay@cs.byu.edu</a>><br>
>> Assistant Professor / Brigham Young University<br>
>> <a href="http://faculty.cs.byu.edu/~jay" target="_blank">http://faculty.cs.byu.edu/~jay</a><br>
>><br>
>> "The glory of God is Intelligence" - D&C 93<br>
>><br>
>> ____________________<br>
>> Racket Users list:<br>
>> <a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
><br>
><br>
<br>
<br>
<br>
--<br>
Jay McCarthy <<a href="mailto:jay@cs.byu.edu">jay@cs.byu.edu</a>><br>
Assistant Professor / Brigham Young University<br>
<a href="http://faculty.cs.byu.edu/~jay" target="_blank">http://faculty.cs.byu.edu/~jay</a><br>
<br>
"The glory of God is Intelligence" - D&C 93<br>
</div></div></blockquote></div><br></div>