ReferenceCounted

A reference-counted object that requires explicit deallocation. <p> When a new {@link ReferenceCounted} is instantiated, it starts with the reference count of {@code 1}. {@link #retain()} increases the reference count, and {@link #release()} decreases the reference count. If the reference count is decreased to {@code 0}, the object will be deallocated explicitly, and accessing the deallocated object will usually result in an access violation. </p> <p> If an object that implements {@link ReferenceCounted} is a container of other objects that implement {@link ReferenceCounted}, the contained objects will also be released via {@link #release()} when the container's reference count becomes 0. </p>

Members

Functions

refCnt
int refCnt()

Returns the reference count of this object. If {@code 0}, it means this object has been deallocated.

release
bool release(int decrement)

Decreases the reference count by the specified {@code decrement} and deallocates this object if the reference count reaches at {@code 0}.

release
bool release()

Decreases the reference count by {@code 1} and deallocates this object if the reference count reaches at {@code 0}.

retain
ReferenceCounted retain()

Increases the reference count by {@code 1}.

retain
ReferenceCounted retain(int increment)

Increases the reference count by the specified {@code increment}.

touch
ReferenceCounted touch()

Records the current access location of this object for debugging purposes. If this object is determined to be leaked, the information recorded by this operation will be provided to you via {@link ResourceLeakDetector}. This method is a shortcut to {@link #touch(Object) touch(null)}.

touch
ReferenceCounted touch(Object hint)

Records the current access location of this object with an additional arbitrary information for debugging purposes. If this object is determined to be leaked, the information recorded by this operation will be provided to you via {@link ResourceLeakDetector}.

Meta