/AutoHotkey.docset/Contents/Resources/Documents/commands/ObjAddRef.htm
HTML | 56 lines | 42 code | 14 blank | 0 comment | 0 complexity | ee1fbb96fb8b9da9e16c74e393a86a69 MD5 | raw file
- <!DOCTYPE HTML>
- <html>
- <head>
- <title>ObjAddRef() / ObjRelease()</title>
- <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <link href="../static/theme.css" rel="stylesheet" type="text/css" />
- <script src="../static/content.js" type="text/javascript"></script>
- </head>
- <body>
- <h1>ObjAddRef() / ObjRelease() <span class="ver">[AHK_L 53+]</span></h1>
- <p>Increments or decrements an object's reference count.</p>
- <pre class="Syntax">ObjAddRef(Ptr)<br>ObjRelease(Ptr)</pre>
- <h3>Parameters</h3>
- <dl>
- <dt>Ptr</dt>
- <dd><p>An unmanaged object pointer or COM interface pointer.</p></dd>
- </dl>
- <h3>Return Value</h3>
- <p>These functions return the new reference count. This value should be used <b>only</b> for debugging purposes.</p>
- <h3>Related</h3>
- <p>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: <a href="http://msdn.microsoft.com/en-us/library/ms691379.aspx">IUnknown::AddRef</a>, <a href="http://msdn.microsoft.com/en-us/library/ms682317.aspx">IUnknown::Release</a>, <a href="http://support.microsoft.com/kb/104138">Reference Counting Rules</a>.</p>
- <h3>Examples</h3>
- <p>See <a href="ComObjConnect.htm#Examples">ComObjConnect</a>.</p>
- <pre class="NoIndent">obj := Object()
- <em>; The following two lines are equivalent:</em>
- ptr1 := <a href="../Objects.htm#AddressCast">Object</a>(obj)
- ptr2 := ObjectToPointer(obj)
- ObjectToPointer(obj) {
- if !IsObject(obj)
- return ""
- ptr := &obj
- ObjAddRef(ptr)
- return ptr
- }
- <em>; 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.</em>
- ObjRelease(ptr2)
- ObjRelease(ptr1)
- </pre>
- </body>
- </html>