Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8184166

SortedList does not free up memory

    Details

    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description

      FULL PRODUCT VERSION :
      java version "1.8.0_66"
      Java(TM) SE Runtime Environment (build 1.8.0_66-b18)
      Java HotSpot(TM) 64-Bit Server VM (build 25.66-b18, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      A DESCRIPTION OF THE PROBLEM :
      SortedList keeps a private Element<E>[] sorted
      This array is expanded when the source list grows. When the source list shrinks, the old elements are kept in the array and cannot be garbage collected.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the provided test code. Set a break point at observableList.clear();
      After observableList.clear(); has been executed, perform garbage collection (e.g. from VisualVM) and generate a heap dump.



      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      No more instances of Person in the heap after garbage collection.
      ACTUAL -
      There are still 10,000 instances of Person in the heap after garbage collection.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javafx.collections.FXCollections;
      import javafx.collections.ObservableList;
      import javafx.collections.transformation.SortedList;

      import org.apache.commons.lang3.RandomStringUtils;

      public class Main {

      public static void main(final String[] args) {
      final ObservableList<Person> observableList = FXCollections.observableArrayList();
      final SortedList<Person> sortedList = new SortedList<>(observableList);
      for (int i = 0; i < 100000; i++) {
      observableList.add(new Person(RandomStringUtils.randomAlphanumeric(64)));
      }
      observableList.clear();
      }

      public static class Person {
      String name;

      public Person(final String name) {
      this.name = name;
      }
      }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Get the "sorted" array by reflection and set all elements between size and sorted.length to null.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

              • Created:
                Updated: