Gocator Development Kit
 All Classes Files Functions Variables Typedefs Friends Modules Pages
Memory Management

Proper attention should be paid to memory management because it is critical to the reliable operation of the sensor.

A small leak can accumulate over time and cause the sensor to fail unexpectedly. To ensure proper memory management, the following guidelines should be followed:

  • Memory allocated in the Start call should be freed in the Stop call.
  • Memory allocated in the Process call should be either freed before the call exits, or transferred to the framework for transmission.

Exceptions to the above guidelines can be made at the discretion of the developer. For example it may be useful in some situations to keep a singleton object allocated throughout multiple Start/Stop cycles.

Objects are transferred to the framework when they are sent by methods such as GdkToolOutput_SetRendering. Any object owned by transferred objects are also transferred.

Objects can be explicitly freed by using kObject_Destroy or kObject_Dispose. For generic containers such as kArrayList or kArray1, kObject_Destroy frees only the parent object but not any contained objects, whereas kObject_Dispose frees all objects that are ultimately contained, including nested objects. Non-generic containers such as GdkGraphic usually are completely freed by a Destroy call. If you are uncertain, kObject_Dispose is almost always safe to use. Please refer to kObject for details.