Disposable

A base class that implements the IDisposable pattern correctly

Disposable Object ensures proper cleanup of both managed and unmanaged resources. It provides a structured way to handle resource disposal and helps prevent memory leaks in your Unity applications.

Package Info

display name

AceLand Disposable

package name

latest version

1.0.0

namespace

dependencies


Features

  • Automatic disposal state tracking

  • Separate handling for managed and unmanaged resources

  • Protection against multiple disposals

  • Proper implementation of IDisposable pattern

  • GC optimization through SuppressFinalize


Usage Example

Override DisposeManagedResources

Override this method to clean up managed resources:

Override DisposeUnmanagedResources

Override this method to clean up unmanaged resources:


Best Practices

  • Always use using statements when possible

  • Check Disposed property before operations:

  • Don't call base methods when overriding:

  • Handle disposal in a deterministic manner:


Important Considerations

  • Override DisposeManagedResources for IDisposable objects

  • Override DisposeUnmanagedResources for native resources

  • Don't throw exceptions from Dispose methods

  • Always check Disposed state in public methods

  • Use try-finally blocks for critical cleanup operations


Last updated