# Class goog.Disposable

code »

All implemented interfaces:
  `goog.disposable.IDisposable`

Class that provides the basic implementation for disposable objects. If your class holds one or more references to COM objects, DOM nodes, or other disposable objects, it should extend this class or implement the disposable interface (defined in goog.disposable.IDisposable).

## Constructor

goog.Disposable ( )

## Enumerations

goog.Disposable.MonitoringMode
  No Description.

Show:Public Protected Private

## Instance Methods

code »`<T>` addOnDisposeCallback ( callback, opt_scope )

Invokes a callback function when this object is disposed. Callbacks are invoked in the order in which they were added.

Parameters

callback: `function(this: T): ?`
  The callback function.
opt_scope: `T=`
  An optional scope to call the callback in.

code »dispose ( ) ⇒ `void`

Disposes of the object. If the object hasn't already been disposed of, calls `#disposeInternal`. Classes that extend `goog.Disposable` should override `#disposeInternal` in order to delete references to COM objects, DOM nodes, and other disposable objects. Reentrant.

Returns

Nothing.

code »disposeInternal ( )

Deletes or nulls out any references to COM objects, DOM nodes, or other disposable objects. Classes that extend `goog.Disposable` should override this method. Not reentrant. To avoid calling it twice, it must only be called from the subclass' `disposeInternal` method. Everywhere else the public `dispose` method must be used. For example:

       mypackage.MyClass = function() {
         mypackage.MyClass.base(this, 'constructor');
         // Constructor logic specific to MyClass.
         ...
       };
       goog.inherits(mypackage.MyClass, goog.Disposable);

       mypackage.MyClass.prototype.disposeInternal = function() {
         // Dispose logic specific to MyClass.
         ...
         // Call superclass's disposeInternal at the end of the subclass's, like
         // in C++, to avoid hard-to-catch issues.
         mypackage.MyClass.base(this, 'disposeInternal');
       };

code »getDisposed ( ) ⇒ `boolean`
Deprecated: Use `#isDisposed` instead.

Returns

Whether the object has been disposed of.

code »isDisposed ( ) ⇒ `boolean`

Returns

Whether the object has been disposed of.

code »registerDisposable ( disposable )

Associates a disposable object with this object so that they will be disposed together.

Parameters

disposable: `goog.disposable.IDisposable`
  that will be disposed when this object is disposed.

## Instance Properties

code »creationStack : `string`

If monitoring the goog.Disposable instances is enabled, stores the creation stack trace of the Disposable instance.

code »disposed_ : `boolean`

Whether the object has been disposed of.

code »onDisposeCallbacks_ : `Array`

Callbacks to invoke when this object is disposed.

## Static Functions

code »goog.Disposable.clearUndisposedObjects ( )

Clears the registry of undisposed objects but doesn't dispose of them.

code »goog.Disposable.getUndisposedObjects ( ) ⇒ `!Array`

Returns

All `goog.Disposable` objects that haven't been disposed of.

code »goog.Disposable.isDisposed ( obj ) ⇒ `boolean`

Returns True if we can verify the object is disposed. Calls `isDisposed` on the argument if it supports it. If obj is not an object with an isDisposed() method, return false.

Parameters

obj: `*`
  The object to investigate.

Returns

True if we can verify the object is disposed.

## Static Properties

code »goog.Disposable.instances_ : `!Object.<number>`

Maps the unique ID of every undisposed `goog.Disposable` object to the object itself.

## Compiler Constants

code »goog.Disposable.INCLUDE_STACK_ON_CREATION : `boolean`
code »goog.Disposable.MONITORING_MODE : `number`