You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by smallufo <sm...@gmail.com> on 2010/09/26 03:53:25 UTC
Is it a good practice to use intern() in all ids ?
I am using a profiler to analyze an OOM heap-dump file , and find tons of
duplicated Strings .
These strings are mostly IDs of wicket components or PropertyModel's
expression ...
I wonder if it a good practice to "intern()" all these Strings ?
such as :
private final static String TIME_STR = "time".intern();
add(new Label(TIME_STR , foobar));
Re: Is it a good practice to use intern() in all ids ?
Posted by James Carman <ja...@carmanconsulting.com>.
If you use literal strings, they will be interned automatically.
On Sat, Sep 25, 2010 at 9:53 PM, smallufo <sm...@gmail.com> wrote:
> I am using a profiler to analyze an OOM heap-dump file , and find tons of
> duplicated Strings .
> These strings are mostly IDs of wicket components or PropertyModel's
> expression ...
> I wonder if it a good practice to "intern()" all these Strings ?
>
> such as :
>
> private final static String TIME_STR = "time".intern();
> add(new Label(TIME_STR , foobar));
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Is it a good practice to use intern() in all ids ?
Posted by Jeremy Thomerson <je...@wickettraining.com>.
>
> I wouldn't do that. You'll most likely run into performance issues.
> Duplicate strings should only arise with the use of new String(). Explicitly
> calling intern() could cause an unexpected amount of memory usage in
> PermGen.
I think you have this backwards. As James mentioned on this thread, string
literals in your code are automatically interned, so there is no need to do
what he is asking, because it is done by the compiler.
http://download.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#intern()
--
Jeremy Thomerson
http://www.wickettraining.com
Re: Is it a good practice to use intern() in all ids ?
Posted by Richard Frovarp <rf...@apache.org>.
On 9/25/2010 8:53 PM, smallufo wrote:
> I am using a profiler to analyze an OOM heap-dump file , and find tons of
> duplicated Strings .
> These strings are mostly IDs of wicket components or PropertyModel's
> expression ...
> I wonder if it a good practice to "intern()" all these Strings ?
>
> such as :
>
> private final static String TIME_STR = "time".intern();
> add(new Label(TIME_STR , foobar));
>
I wouldn't do that. You'll most likely run into performance issues.
Duplicate strings should only arise with the use of new String().
Explicitly calling intern() could cause an unexpected amount of memory
usage in PermGen.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org