diff --git a/src/main/java/org/scijava/Context.java b/src/main/java/org/scijava/Context.java index e4d2bda14..2576b4c37 100644 --- a/src/main/java/org/scijava/Context.java +++ b/src/main/java/org/scijava/Context.java @@ -58,7 +58,7 @@ * @author Curtis Rueden * @see Service */ -public class Context implements Disposable { +public class Context implements Disposable, AutoCloseable { // -- Constants -- @@ -248,6 +248,13 @@ public Context(final Collection> serviceClasses, * those of lower priority). See {@link ServiceHelper#loadServices()} for more * information. *

+ *

+ * NB: Instiantiation of a Context has an implied requirement of a + * corresponding call to {@link Context#dispose()} at the end of the SciJava + * applicaton's lifecycle. This cleans up any remaining resources and allows + * the JVM to exit gracefully. This is called automatically when constructed as + * an {@link AutoCloseable}. + *

* * @param serviceClasses A collection of types that implement the * {@link Service} interface (e.g., {@code DisplayService.class}). @@ -423,6 +430,13 @@ public void dispose() { } } + // -- AutoCloseable methods -- + + @Override + public void close() throws Exception { + dispose(); + } + // -- Utility methods -- /**