-
Notifications
You must be signed in to change notification settings - Fork 18
ref_iface_IVDXUnknown_Release
VirtualDub Plugin SDK 1.2
IVDXUnknown interface
Decrements the reference count on an object and destroys it if the reference count is zero.
int Release();
This method is not thread-safe.
Errors may not be returned from this function (see SetError()).
A non-negative value indicating the new reference count on the object. A return value of zero indicates that the object was destroyed.
The IVDXUnknown::Release() method is very similar to the IUnknown::Release() method in the Microsoft Component Object Model (COM). It is used to drop an independent strong reference on the object; the object is automatically destroyed when all strong references are gone.
As Release() may be called more widely than the other methods on an object, initialization or other types of nontrivial processing must not be done in Release(). Release() must not call into any callbacks within the host, nor may it fail.
It is vitally important that the reference count be maintained in a thread-safe manner, as AddRef() and Release() may be called from multiple threads even on an object whose functional methods are not thread-safe. The simplest way to do this is through the InterlockedIncrement() and InterlockedDecrement() methods in the Win32 Platform SDK:
int MyClass::Release() {
int newRefCount = (int)InterlockedDecrement(&mRefCount);
if (!newRefCount)
delete this;
return newRefCount;
}
In Visual C++, the _InterlockedIncrement() and _InterlockedDecrement() intrinsics may be used.
An implementation of Release() must not read an internal reference count variable more than once, as this can lead to failures. The following implementation is incorrect:
int MyClass::Release() {
int newRefCount = (int)InterlockedDecrement(&mRefCount);
// This is incorrect, as two threads may see mRefCount go to zero, causing the
// object to be destroyed twice.
if (!mRefCount)
delete this;
// This is incorrect, as the reference count variable may be read after the enclosing
// object is destroyed.
return mRefCount;
}
Copyright (C) 2007-2012 Avery Lee.
Setting up your development environment
Conventions
Plugin initialization
Dynamic loading
Reference counting
Using CPU extensions
Introduction
What's new
Breaking changes
Gotchas
Deprecated features
Migrating from the old Filter SDK
Programming model
Handling bitmaps
Creating a video filter
Setting filter parameters
Processing video frames
Managing filter data
Creating time-varying filters
Handling aspect ratio
Prefetching multiple source frames
Handling multiple sources
Making a filter configurable
Scripting support
CPU dependent optimization
VDXA index omitted
Getting started
Writing the module entry point
Creating a video filter
Adding configurability
Adding script support
Introduction
What's new
Autodetect
Direct mode
Video frames vs. samples
Video decodint model
Video decoder