Creation and Destruction Routines
The following routines can be used to create and destroy ObjectTools objects. You must successfully create a valid object before using any other ObjectTools routine.
OT New version 1
| OT New → Longint | |||
|---|---|---|---|
| Parameter | Type | Description | |
| Function result | Longint | ← | A handle to a new, empty object |
| Discussion | |||
Creates a new, empty object and returns it. The new object is added to internal list of objects. When you are finished with the object, call OT Clear to release the memory used by the object.
Warning Never attempt to pass any value to an ObjectTools routine other than that returned by OT New.
See Also
OT Clear version 1
OT Clear(ioObject)
| Parameter | Type | Description | |
| ioObject | Longint | ↔ | A handle to an object |
| Discussion |
When you are finished with an object, you should always call OT Clear to release the memory occupied by the object. If you create an object and then lose track of its handle, you will no longer be able to release its memory. This is known as a leak, and it is considered a Bad Thing.
ObjectTools maintains an internal list of all objects that have been created but not cleared. When an object is disposed of with OT Clear, it is removed from the list. The current list of created objects is available with the OT GetHandleList method.
You can actually release the memory used by leaked objects with OT GetHandleList or OT ClearAll. However, using these as a means of object memory management is not recommended.
It you pass a variable directly to OT Clear (as opposed to an extremely lucky guess at a number constant), the variable will be set to zero.
Note It is legal to pass a null handle (0) to OT Clear.
Examples
The sample code is below demonstrates creating two temporary objects to pass to a method. The first one will leak, while the second one is properly disposed with OT Clear.
C_LONGINT($leak;$notLeak)$leak:=OT New
OT PutString ($leak;"name";[Contacts]Name)
$notLeak:=OT New
OT PutString ($notLeak;"address";[Contacts]Address)
MyMethod($leak;$notLeak)
OT Clear ($notLeak) `The memory is released
`If we leave this method at this point, we will not be able to recover
`the value of $leak, so its memory will leak.
See Also

