$ java --enable-preview -Xmx6g ScopedValueVsThreadLocalMemory 500000 (JDK 25) threads per scenario: 500000, 5 bound values each, forked via StructuredTaskScope CHECK ok : every one of 1000 subtasks read all 5 scoped values correctly CHECK ok : every one of 1000 subtasks read all 5 inherited ThreadLocal values correctly CHECK ok : every one of 500000 subtasks read all 5 scoped values correctly ScopedValue: 500000 live subtasks, 5 bound values each, heap delta = 531.8 MB (1115 bytes/thread) CHECK ok : every one of 500000 subtasks read all 5 inherited ThreadLocal values correctly ThreadLocal: 500000 live subtasks, 5 inherited values each, heap delta = 546.1 MB (1145 bytes/thread) ThreadLocal used 1.0x the heap ScopedValue used, for holding the identical 5 values live on 500000 threads exit=0