Loading... (original) (raw)

From mailing list. The following code provokes a memory leak:

import jdk.jfr.consumer.RecordingStream;

public class RecordingStreamTest {

public static byte[] bytes;

public static void main(String[] args) throws Exception {
RecordingStream stream = new RecordingStream();
stream.enable("jdk.ObjectAllocationInNewTLAB");
stream.enable("jdk.ObjectAllocationOutsideTLAB");
stream.onEvent(re -> {});
stream.startAsync();

for (int j = 1; j <= 5; j++) {
for (int i = 1; i <= 100_000_000; i++) {
bytes = new byte[1024];
}

System.gc();
}

stream.close();
stream.awaitTermination();

System.gc();

Thread.sleep(5000);
}
}