Deallocate user memory
The database server does not perform any automatic reclamation of user memory in a client LIBMI application. Therefore, the client LIBMI application must use mi_free() to explicitly free all allocations that mi_alloc() makes.
User memory remains valid until whichever of the following
events occurs first:
- The mi_free() function frees the memory.
- The mi_close() function closes the current connection.
- The client LIBMI application ends.
To conserve resources, use the mi_free() function
to explicitly deallocate the user memory once your DataBlade
API module
no longer needs it. The mi_free() function is the
destructor function for user memory.
Important: Use mi_free() only
for user memory that you have explicitly allocated with mi_alloc(), mi_dalloc(),
or mi_zalloc(). Do not use this function to free
structures that other DataBlade
API functions
allocate.
Keep the following restrictions in mind about memory deallocation:
- Do not free user memory that you allocate for the return value of a UDR.
- Do not free memory until you are finished accessing the memory.
- Do not use mi_free() to deallocate memory that you have not explicitly allocated.
- Do not use mi_free() for data type structures that other DataBlade API constructor functions allocate.
- Do not attempt to free user memory after its memory duration expires.
- Reuse memory whenever possible. Do not repeat calls to allocation functions if you can reuse the memory for another task.