PageRenderTime 28ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/AutoHotkey.docset/Contents/Resources/Documents/commands/ObjAddRef.htm

https://gitlab.com/ahkscript/Autohotkey.docset
HTML | 56 lines | 42 code | 14 blank | 0 comment | 0 complexity | ee1fbb96fb8b9da9e16c74e393a86a69 MD5 | raw file
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <title>ObjAddRef() / ObjRelease()</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  6. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  7. <link href="../static/theme.css" rel="stylesheet" type="text/css" />
  8. <script src="../static/content.js" type="text/javascript"></script>
  9. </head>
  10. <body>
  11. <h1>ObjAddRef() / ObjRelease() <span class="ver">[AHK_L 53+]</span></h1>
  12. <p>Increments or decrements an object's reference count.</p>
  13. <pre class="Syntax">ObjAddRef(Ptr)<br>ObjRelease(Ptr)</pre>
  14. <h3>Parameters</h3>
  15. <dl>
  16. <dt>Ptr</dt>
  17. <dd><p>An unmanaged object pointer or COM interface pointer.</p></dd>
  18. </dl>
  19. <h3>Return Value</h3>
  20. <p>These functions return the new reference count. This value should be used <b>only</b> for debugging purposes.</p>
  21. <h3>Related</h3>
  22. <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>
  23. <h3>Examples</h3>
  24. <p>See <a href="ComObjConnect.htm#Examples">ComObjConnect</a>.</p>
  25. <pre class="NoIndent">obj := Object()
  26. <em>; The following two lines are equivalent:</em>
  27. ptr1 := <a href="../Objects.htm#AddressCast">Object</a>(obj)
  28. ptr2 := ObjectToPointer(obj)
  29. ObjectToPointer(obj) {
  30. if !IsObject(obj)
  31. return ""
  32. ptr := &amp;obj
  33. ObjAddRef(ptr)
  34. return ptr
  35. }
  36. <em>; Each pointer retrieved via Object() or ObjectToPointer() must be manually released
  37. ; to allow the object to be eventually freed and any memory used by it reclaimed.</em>
  38. ObjRelease(ptr2)
  39. ObjRelease(ptr1)
  40. </pre>
  41. </body>
  42. </html>