public interface Disposable
Disposable
interface defines a method to release allocated
resource.
The primary use of this interface is to release system resources. The garbage collector automatically releases the memory allocated to a Java object when that object is no longer used. However, it is not possible to predict when garbage collection will occur. Furthermore, the garbage collector has no knowledge of system resources such as window handles, or open files and streams.
Use the dispose
method of this interface to explicitly release
system resources in conjunction with the garbage collector. The consumer of
an object can call this method when the object is no longer needed.
Modifier and Type | Method and Description |
---|---|
void |
dispose()
Performs application-defined tasks associated with freeing, releasing, or
resetting system resources.
|
void dispose()
Use this method to close or release system resources such as files, streams, and handles held by an instance of the class that implements this interface.
When implementing this method, ensure that all held resources are freed
by propagating the call through the containment hierarchy. For example,
if an object A allocates an object B, and object B allocates an object C,
then A's dispose
implementation must call
dispose
on B, which must in turn call dispose
on C. An object must also call the dispose
method of its
base class if the base class implements Disposable
.
If an object's dispose
method is called more than once, the
object must ignore all calls after the first one. The object must not
throw an exception if its dispose
method is called multiple
times. Instance methods other than dispose
can throw an
exception when resources are already disposed.
Copyright © 2009 - 2016 DataGis. All Rights Reserved.