ObjAddRef() / ObjRelease

Auto Hotkey

ObjAddRef() / ObjRelease()

Increments or decrements an object's reference count.

OutputVar := ObjAddRef(Ptr)
OutputVar := ObjRelease(Ptr)
Function Example: RefCount := ObjAddRef(&obj;)

Parameters

OutputVar

The name of the variable in which to store the new reference count.

Ptr

An unmanaged object pointer or COM interface pointer.

General Remarks

Reference count should be used only for debugging purposes.

Related

Reference Counting

Although the following articles discuss reference counting as it applies to COM, they cover some important concepts and rules which generally also apply to AutoHotkey objects: IUnknown::AddRef, IUnknown::Release, Reference Counting Rules.

Examples

See ComObjConnect.

obj := Object()

; The following two lines are equivalent:
ptr1 := Object(obj)
ptr2 := ObjectToPointer(obj)

ObjectToPointer(obj) {
    if !IsObject(obj)
        return ""
    ptr := &obj
    ObjAddRef(ptr)
    return ptr
}

; Each pointer retrieved via Object() or ObjectToPointer() must be manually released
; to allow the object to be eventually freed and any memory used by it reclaimed.
ObjRelease(ptr2)
ObjRelease(ptr1)