IDisposable Interface

Interface adopted by a type which has deterministic cleanup logic. For example:

  • Most rendering-related types, such as RenderGraphic and Viewport, own WebGL resources which must be explicitly released when no longer needed.
  • Some low-level objects like ECDb own native types defined in C++ code which must be explicitly released when no longer needed.

A similar concept exists in languages like C++ (implemented as "destructors") and C# ("IDisposable"). However, because TypeScript and Javascript lack any built-in support for deterministic destruction, it is up to the programmer to ensure dispose() is called appropriately. Failure to do so may result in memory leaks or leaking of other resources.

IDisposable tends to be contagious; that is, if a type has members which implement IDisposable, that type should also implement IDisposable to dispose of those members.

Implementations of IDisposable tend to be more "low-level" types. The disposal of such types is often handled on your behalf by imodel.js. However, always consult the documentation for an IDisposable type to determine under what circumstances you are expected to explicitly dispose of it.

Implemented by

Methods

Name Description
dispose(): void Disposes of any resources owned by this object.  

Defined in

Last Updated: 20 September, 2019