On 10/30/17 1:49 PM, Peter Levart wrote:
...above example lends itself as a use case for the following equivalent alternative using internal low-level API where ZStreamRef becomes the Cleanable itself:class ZStreamRef extends PhantomCleanable<Object> { private final LongConsumer end; private volatile long address; ZStreamRef (Object referent, LongSupplier init, LongConsumer end) {// here the registration MUST happen as 1st thing - enforced by javacsuper(referent, CleanerFactory.cleaner()); this.end = end; this.address = init.getAsLong(); } long address() { return address; } @Override protected void performCleanup() { long addr = address; address = 0; if (addr != 0) { end.accept(addr); } } }
I was thinking something along this line what could ensure the "cleanable" object is allocated before allocating the resources that the cleanable is responsible for clean up. I think it'd be a good RFE to improve the Cleaner API to address the OOM case.
Mandy
