Proposal: Automatic Resource Management

Bob Lee crazybob at crazybob.org
Fri Mar 6 13:11:06 PST 2009


The "finally" modifier is very clever, but I think we're underestimating its
complexity and overestimating its benefits. All of the use cases I've seen
can be supported by pure syntax sugar based on two interfaces:
Disposable.dispose() and Resource.close().

I've come across one exception: Apache HttpClient. It just so happens I'm a
contributer to that project, and I'd rather make HttpResponse implement
Closeable than add the complexity of supporting "finally" to the language.

In other words, I'd much rather us adapt our APIs to support a very simple
language feature than add a complex feature like the finally modifier,
modify the bytecode format, etc. The examples where the interface-based
approach works well are too numerous to count. Does anyone have real world
examples where adapting an API to work with Disposable or Resource would be
so egregious as to justify the complexity inherent in the finally modifier?
Please limit examples to only those that you would actually want to use with
this language construct. For example, Lock.unlock() and Process.destroy()
don't count, but this construct would certainly come in handy for
Process.getInputStream/OutputStream/ErrorStream().

Bob



More information about the coin-dev mailing list