Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-31435

Replace String.intern() by WeakHashMap in Maven Plugin to avoid memory leaks

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • maven-plugin
    • None

      The issue has been discovered by schristou

      Ok after doing far more investigating on this issue I found out that actually the String.intern() in JDK7 actually uses a String pool to handle the strings. It does not go to pergmen (See http://bugs.java.com/view_bug.do?bug_id=6962931). See also http://java-performance.info/string-intern-in-java-6-7-8/.

      I remember investigating their memory leak issue and I found it to be related to the ModuleDependency in the maven plugin. If you look at: https://github.com/jenkinsci/maven-plugin/blob/master/src/main/java/hudson/maven/ModuleDependency.java#L111

      We are doing a String.intern on the version number which I'd assume consumes the String pool. If we're interning the version number for each maven project I bet this could cause a memory leak fairly quick. The reason why is if I create a new version number for each build (continuous delivery), then I'm interning the string each time.

      Such memory leak may happen in GCs like ParallelGC: http://stackoverflow.com/questions/2431540/garbage-collection-behaviour-for-string-intern .

          [JENKINS-31435] Replace String.intern() by WeakHashMap in Maven Plugin to avoid memory leaks

          James Nord added a comment -

          where is the leak?

          The referenced stack overflow says "since the interned string pool is a static member of the String class and will never be garbage collected." But well it's not and this was written in 2010 which was way before the initial java 1.7 release.

          We also require JDK7 to run - so I fail to see how anything relavent to 1.6 requires us to do anything.

          James Nord added a comment - where is the leak? The referenced stack overflow says "since the interned string pool is a static member of the String class and will never be garbage collected." But well it's not and this was written in 2010 which was way before the initial java 1.7 release. We also require JDK7 to run - so I fail to see how anything relavent to 1.6 requires us to do anything.

            Unassigned Unassigned
            oleg_nenashev Oleg Nenashev
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: