In article <email@example.com.OZ.AU>,
Andrew Bromage <firstname.lastname@example.org.OZ.AU> wrote:
>>They may need to be distinguished for the purpose of compile-time
>>garbage collection. If you create two immutable identical objects,
>>it may be easier to discover when they become garbage because the
>>references to them are unique, than if they were one object with
>>a shared reference.
>>Admittedly the programmer does not necessarily need to see this.
email@example.com (Patrick Doyle) writes:
> Neither does the GC. It can simply throw away one of the objects
>immediately and use the other, can't it?
In some languages (Clean and Mercury spring to mind immediately)
you can mark some objects as being "unique" or "linear" in either the
type system, or the mode system if it's a language which supports
multiple modes of procedures. Such objects are not mutable, but it
is possible for the compiler to know when all references to such an
object are dead and you can generate code to reuse or reclaim the
object, saving the overhead of reclaiming, and potentially the cost
of reallocating, the object.