commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rich Dougherty <>
Subject Re: [lang] Pooled and mutable numbers. / ObjectUtils interner?
Date Wed, 12 Mar 2003 20:41:37 GMT
> I don't fully understand the String.intern() method.  I understand the
> purpose, but to be able to call String.intern(), don't you need to
> create a new instance of a String to then check if it has already been
> created?  (The same thought that Rich D had about his Interner class). 
> I thought that the functionality of String.intern() is something that
> the JRE performs by default, as opposed to having to be called manually.

I think the point is to (a) reduce memory usage and (b) increase the 
efficiency of comparisons. Once example of intern() in action is in Jython.

Jython interns all identifiers when it parses them. This means it can 
perform comparisons and lookups very efficiently. Also, size of the 
program is reduced since identifiers are only stored in memory once.

Each identifier is created as a separate object when it is parsed. After 
the identifier has been interned, the original object would be garbage 
collected. So, using intern() doesn't reduce the amount of object 
creation. But, for Jython, the performance and memory benefits made 
intern() worthwhile.

This thread started as an idea for an object that combined a factory 
with a pool to (a) reduce memory usage, (b) increase the efficiency of 
comparisons and (c) reduce the amount of object creation/garbage 
collection. String.intern() and the Interner class I posted can provide 
(a) and (b), but don't address (c).


View raw message