You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by "Sven Meier (JIRA)" <ji...@apache.org> on 2015/11/13 21:52:11 UTC

[jira] [Commented] (WICKET-6033) [Possible Memory Leak]RepeatingView Should not use String.intern

    [ https://issues.apache.org/jira/browse/WICKET-6033?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15004697#comment-15004697 ] 

Sven Meier commented on WICKET-6033:
------------------------------------

String interning was introduced with commit 8f6f59ecddcb927aa68f8afb23b973854062de9d by [~mgrigorov].

According to http://java-performance.info/string-intern-in-java-6-7-8/ this should cause no troubles under Java 7 and 8, at least no OOMEs.

> [Possible Memory Leak]RepeatingView Should not use String.intern
> ----------------------------------------------------------------
>
>                 Key: WICKET-6033
>                 URL: https://issues.apache.org/jira/browse/WICKET-6033
>             Project: Wicket
>          Issue Type: Bug
>          Components: wicket
>    Affects Versions: 7.1.0
>            Reporter: Cleber Muramoto
>            Priority: Trivial
>
> RepeatingView uses String.intern in order to generate sequential ids.
> There are two problems with this approach:
> 1)It doesn't actually prevent Object allocation (A new String is created before it is replaced by the interned one)
> 2)It can fill the JVM StringTable (whose size can be configured with -XX:StringTableSize)
> Usually the counter will not grow too large, however when using AjaxSelfUpdatingBehavior this might happen.
> Let's suppose one have has to provide a screen which displays a self-updating table with about 30 rows, to an user with no session timeout. Every Ajax update will cause 30 new ids to be generated, unless the RepeatingView is re-created from scratch. If the refresh rate is about 10s, in a 24h period that little repeater will cause 259200 strings to be interned!
> I think that it might be better if Wicket used an id cache in order to optimize the mapping int->String.
> public static final String[] IDS = new String[Integer.getInteger("some_property", 1024)];
> public static final String id(final int ix) {
> 		String id = null;
> 		if (ix < IDS.length) {
> 			id = IDS[ix];
> 			if (id == null) {
> 				id = String.valueOf(ix);
> 				IDS[ix] = id;
> 			}
> 		} else {
> 			id = String.valueOf(ix);
> 		}
> 		return id;
> }
> This approach would prevent Object allocation and wouldn't mess with JVM's String table.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)