| 2113 | |
| 2114 | |
| 2115 | bool GuiType::Delete() // IObject::Delete() |
| 2116 | { |
| 2117 | // Delete() should only be called when the script releases its last reference to the |
| 2118 | // object, or when the user closes the window while the script has no references. |
| 2119 | // See VisibilityChanged() for details. |
| 2120 | if (mHwnd) |
| 2121 | Destroy(); |
| 2122 | else |
| 2123 | Dispose(); |
| 2124 | // OnMessage() or perhaps some other callback may enable the script to regain a ref. |
| 2125 | // Although the object is now unusable, for program stability we must `delete this` |
| 2126 | // only if mRefCount is still 1 (it's never decremented to 0). |
| 2127 | if (mRefCount > 1) |
| 2128 | return false; |
| 2129 | return Object::Delete(); |
| 2130 | } |
| 2131 | |
| 2132 | |
| 2133 | |