void () { for (int i = 0; i < 1000; i++) { TaskWithEquivalentObject task = new TaskWithEquivalentObject("q-" + i) { @Override public void perform(@NotNull ProgressIndicator indicator) { } }; myQueue.addTask(task); if (i % 3 == 0) { Disposer.dispose(task); } if (i % 3 == 1) { myQueue.cancelTask(task); } } runAllTasks(); LeakHunter.checkLeak(myQueue, ProgressIndicator.class); LeakHunter.checkLeak(myQueue, TaskWithEquivalentObject.class); }