« Return to Thread: Literal instance slots, 10 foo := 1

Re: Magic Literal instances

by Steve Dekorte :: Rate this Message:

Reply to Author | View in Thread


On 2009-04-26, at 2:13 AM, spir wrote:
> (works also for longer strings)
> How come literal values can be shared? Have the impression I must be  
> messing up distinct things -- or overlooking something obvious.

String literals are symbols. Symbols are global and there is only one  
instance of each. Even if a symbol isn't referenced, it will live  
until the garbage collector removes it. For example:

Io> "foo" uniqueId
==> 6564192
Io> "foo" uniqueId
==> 6564192
Io> Collector collect
==> 5196
Io> "foo" uniqueId
==> 5405424

 « Return to Thread: Literal instance slots, 10 foo := 1