ObjAddRef() / ObjRelease()

AutoHotkey GUI

ObjAddRef() / ObjRelease() [AHK_L 53+]

Increments or decrements an object's reference count.

ObjAddRef(Ptr)
ObjRelease(Ptr)

Parameters

Ptr

An unmanaged object pointer or COM interface pointer.

Return Value

These functions return the new reference count. This value 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)