Table of Contents

Class CvObject

Namespace
OpenCvSharp
Assembly
OpenCvSharp.dll

Base class for objects that own a single native OpenCV pointer through an OpenCvSafeHandle. The SafeHandle is the single source of truth for the native handle value and is responsible for releasing it (including from its own finalizer when the managed object is dropped without Dispose()).

public abstract class CvObject : IDisposable
Inheritance
CvObject
Implements
Derived
Inherited Members

Constructors

CvObject()

Default constructor

CvObject(OpenCvSafeHandle)

Constructor that accepts an OpenCvSafeHandle. The SafeHandle owns the native resource and will release it on disposal.

CvObject(nint)

Constructor (backward compatibility). Wraps the pointer in a non-owning SafeHandle. Derived classes that own the native resource should call SetSafeHandle(OpenCvSafeHandle) to replace it with an owning handle.

Properties

CvPtr

Native pointer of OpenCV structure

IsDisposed

Gets a value indicating whether this instance has been disposed. Backed by the same once-only flag that guards disposal, so there is no separate state to keep in sync.

ptr

Native data pointer, derived from OpenCvSharp.CvObject.safeHandle. Returns Zero when no SafeHandle has been set.

Methods

Dispose()

Releases the resources

Dispose(bool)

Releases the resources

DisposeManaged()

Releases managed resources, including the SafeHandle if present.

DisposeUnmanaged()

Releases unmanaged resources. Nulls out the SafeHandle so that ptr returns Zero after disposal, providing defence-in-depth against use-after-dispose.

~CvObject()

Destructor

SetPostReleaseAction(Action)

Registers cleanup that runs after the owned native handle is released, including when cleanup is initiated by the SafeHandle finalizer.

SetSafeHandle(OpenCvSafeHandle)

Sets or replaces the internal SafeHandle. The ptr property will reflect the new handle's value.

ThrowIfDisposed()

If this object is disposed, then ObjectDisposedException is thrown.