* Xueming Shen: > It might be possible to try-catch to expect Cleaner.register might > fail, but I doubt it's really necessary here and it is the > recommended usage of Cleaner?
That is actually why I posted this. 8-) For similar functionality in other languages, it is often necessary to perform all the required allocations for cleanup registration upfront, then allocate the resource, and finally install it in the cleanup handler. A straightforward translation to the Cleaner facility and the CleaningExample in the documentation would not allocate the state-to-be-cleaned in the State constructor, but in a separate method which is called after Cleaner.register(). But I don't know if this could run into any concurrency issues.