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

protected CvObject()

CvObject(OpenCvSafeHandle)

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

protected CvObject(OpenCvSafeHandle safeHandle)

Parameters

safeHandle OpenCvSafeHandle

The safe handle wrapping the native pointer.

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.

protected CvObject(nint ptr)

Parameters

ptr nint

Properties

CvPtr

Native pointer of OpenCV structure

public nint CvPtr { get; }

Property Value

nint

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.

public bool IsDisposed { get; }

Property Value

bool

ptr

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

protected nint ptr { get; }

Property Value

nint

Methods

Dispose()

Releases the resources

public void Dispose()

Dispose(bool)

Releases the resources

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

If disposing equals true, the method has been called directly or indirectly by a user's code. Managed and unmanaged resources can be disposed. If false, the method has been called by the runtime from inside the finalizer and you should not reference other objects. Only unmanaged resources can be disposed.

DisposeManaged()

Releases managed resources, including the SafeHandle if present.

protected virtual void DisposeManaged()

DisposeUnmanaged()

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

protected virtual void DisposeUnmanaged()

~CvObject()

Destructor

protected ~CvObject()

SetSafeHandle(OpenCvSafeHandle)

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

protected void SetSafeHandle(OpenCvSafeHandle handle)

Parameters

handle OpenCvSafeHandle

The safe handle wrapping the native pointer.

ThrowIfDisposed()

If this object is disposed, then ObjectDisposedException is thrown.

public void ThrowIfDisposed()