import java.util.ArrayList;
import java.util.List;

public class StableLiveSet {
    // ~300MB of long-lived objects (each entry ~1MB)
    static final List<byte[]> longLived = new ArrayList<>();

    public static void main(String[] args) throws Exception {
        // Create ~300MB of retained objects
        for (int i = 0; i < 300; i++) {
            longLived.add(new byte[1_000_000]); // ~1MB each
        }

        System.out.println("Initialized ~300MB long-lived data. Now allocating...");

        // Keep allocating garbage forever
        while (true) {
            // Allocate 1MB garbage
            byte[] garbage = new byte[1_000_000];

            // Do a little work so JIT doesn't optimize it out
            garbage[0] = 1;

            // Slow down slightly so you can observe GC logs clearly
            Thread.sleep(10);
        }
    }
}