void (@NotNull BooleanSupplier stop) { //long started = System.nanoTime(); ReferenceQueue<Object> q = new ReferenceQueue<>(); SoftReference<Object> ref = new SoftReference<>(new Object(), q); System.gc(); StringBuilder log = new StringBuilder(); if (!allocateTonsOfMemory(log, EmptyRunnable.getInstance(), () -> ref.isEnqueued() || ref.get() == null || stop.getAsBoolean())) { //noinspection UseOfSystemOutOrSystemErr System.out.println("GCUtil.tryGcSoftlyReachableObjects: giving up. Log:\n" + log); } //System.out.println("Done GCing refs:" + ((System.nanoTime() - started) / 1000000)); }