unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Are symbols garbage collected?
@ 2017-10-23 17:49 Christopher Allan Webber
  2017-10-23 18:16 ` Marko Rauhamaa
  2017-10-23 19:03 ` David Kastrup
  0 siblings, 2 replies; 5+ messages in thread
From: Christopher Allan Webber @ 2017-10-23 17:49 UTC (permalink / raw)
  To: guile-user

I thought they weren't but now I'm not really sure where I got that idea
from.  Does anyone know for sure?



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Are symbols garbage collected?
  2017-10-23 17:49 Are symbols garbage collected? Christopher Allan Webber
@ 2017-10-23 18:16 ` Marko Rauhamaa
  2017-10-23 19:35   ` Christopher Allan Webber
  2017-10-23 19:03 ` David Kastrup
  1 sibling, 1 reply; 5+ messages in thread
From: Marko Rauhamaa @ 2017-10-23 18:16 UTC (permalink / raw)
  To: Christopher Allan Webber; +Cc: guile-user

Christopher Allan Webber <cwebber@dustycloud.org>:

> I thought they weren't but now I'm not really sure where I got that
> idea from. Does anyone know for sure?

I don't think the language spec says anything about any particular
object or object type being garbage collected. Symbols are first-class
objects and undergo the same treatment as any other object.


Marko



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Are symbols garbage collected?
  2017-10-23 17:49 Are symbols garbage collected? Christopher Allan Webber
  2017-10-23 18:16 ` Marko Rauhamaa
@ 2017-10-23 19:03 ` David Kastrup
  2017-10-23 19:30   ` Christopher Allan Webber
  1 sibling, 1 reply; 5+ messages in thread
From: David Kastrup @ 2017-10-23 19:03 UTC (permalink / raw)
  To: guile-user

Christopher Allan Webber <cwebber@dustycloud.org> writes:

> I thought they weren't but now I'm not really sure where I got that
> idea from.  Does anyone know for sure?

They are garbage-collected.  This is not overly relevant outside of
C/C++ code since as long as any code references a symbol, it will stay
around.  It's only when you look at things like its address independent
of the symbol that you'd notice.

scheme@(guile-user)> (object-address 'blablaaaaaa)
$4 = 94515697299616
scheme@(guile-user)> (gc)
scheme@(guile-user)> (object-address 'blablaaaaaa)
$5 = 94515696660320
scheme@(guile-user)> 

Similar for hashq: without the symbol being stored somewhere, it will
likely deliver different values each time round.

If you put this into code rather than retyping it on the command line,
the address will be the same each time.  You'd need to use something
like
(string->symbol "blablaaaaaa")
in order to get different addresses: a literal symbol in the code would
be protected.

-- 
David Kastrup




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Are symbols garbage collected?
  2017-10-23 19:03 ` David Kastrup
@ 2017-10-23 19:30   ` Christopher Allan Webber
  0 siblings, 0 replies; 5+ messages in thread
From: Christopher Allan Webber @ 2017-10-23 19:30 UTC (permalink / raw)
  To: David Kastrup; +Cc: guile-user

David Kastrup writes:

> Christopher Allan Webber <cwebber@dustycloud.org> writes:
>
>> I thought they weren't but now I'm not really sure where I got that
>> idea from.  Does anyone know for sure?
>
> They are garbage-collected.  This is not overly relevant outside of
> C/C++ code since as long as any code references a symbol, it will stay
> around.  It's only when you look at things like its address independent
> of the symbol that you'd notice.
>
> scheme@(guile-user)> (object-address 'blablaaaaaa)
> $4 = 94515697299616
> scheme@(guile-user)> (gc)
> scheme@(guile-user)> (object-address 'blablaaaaaa)
> $5 = 94515696660320
> scheme@(guile-user)> 
>
> Similar for hashq: without the symbol being stored somewhere, it will
> likely deliver different values each time round.
>
> If you put this into code rather than retyping it on the command line,
> the address will be the same each time.  You'd need to use something
> like
> (string->symbol "blablaaaaaa")
> in order to get different addresses: a literal symbol in the code would
> be protected.

Thanks for the reply!  That's helpful.  Dave Thompson also did a little
demo for me, and I'm totally convinced that symbols are GC'ed now. :)



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Are symbols garbage collected?
  2017-10-23 18:16 ` Marko Rauhamaa
@ 2017-10-23 19:35   ` Christopher Allan Webber
  0 siblings, 0 replies; 5+ messages in thread
From: Christopher Allan Webber @ 2017-10-23 19:35 UTC (permalink / raw)
  To: Marko Rauhamaa; +Cc: guile-user

Marko Rauhamaa writes:

> Christopher Allan Webber <cwebber@dustycloud.org>:
>
>> I thought they weren't but now I'm not really sure where I got that
>> idea from. Does anyone know for sure?
>
> I don't think the language spec says anything about any particular
> object or object type being garbage collected. Symbols are first-class
> objects and undergo the same treatment as any other object.

Yes, though they are intern'ed, and symbols are not always garbage
collected.  I know in Ruby at one point they were not, I heard today
they aren't in Erlang either, and even until apparently recently they
weren't GC'ed in MIT Scheme I think:

https://www.gnu.org/software/mit-scheme/release.html

  "Symbols can now be garbage-collected." in 9.1 even.. that came out in
  2011!

Anyway it looks like Guile does indeed garbage collect symbols.  I have
no idea how I got the impression that it did not, but it looks like it
isn't unusual for symbols to not be GC'ed in a number of languages.



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-10-23 19:35 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-23 17:49 Are symbols garbage collected? Christopher Allan Webber
2017-10-23 18:16 ` Marko Rauhamaa
2017-10-23 19:35   ` Christopher Allan Webber
2017-10-23 19:03 ` David Kastrup
2017-10-23 19:30   ` Christopher Allan Webber

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).