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

Garbage retention when source CompletableFutures are never completed


    • Type: Bug
    • Status: Open
    • Priority: P3
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:


      If a source CompletableFuture has a completion action with a dependent CompletableFuture, and the dependent future is completed (for example by being cancelled) and the source future is never completed or garbage collected, then a useless Completion is attached to the source future. If it was ever to fire, it would do nothing because the dependent future is already done. If this happens repeatedly, we have a memory leak. One use case for this is creating a dependent future on a source future that represents an exceptional event and is never expected to fire.

      Here's a jsr166 CVS tck test with repro instructions:

           * Checks for garbage retention when a dependent future is
           * cancelled and garbage-collected.
           * As of 2016-07, fails with OOME:
           * ant -Dvmoptions=-Xmx8m -Djsr166.expensiveTests=true -Djsr166.tckTestClass=CompletableFutureTest -Djsr166.methodFilter=testCancelledGarbageRetention tck
          public void testCancelledGarbageRetention() throws Throwable {
              final int n = expensiveTests ? 100_000 : 10;
              CompletableFuture<Integer> neverCompleted = new CompletableFuture<>();
              for (int i = 0; i < n; i++)
                  assertTrue(neverCompleted.thenRun(() -> {}).cancel(true));




            • Assignee:
              martin Martin Buchholz
              martin Martin Buchholz
            • Votes:
              0 Vote for this issue
              2 Start watching this issue


              • Created: