Function _momFree() Foundation

Releases a memory object.

Syntax
XPPAPIRET _momFree(MomHandle hOld);
Parameters
MomHandle hOld
Handle of a memory object that is no longer needed. This object must have been created with _momAlloc().
Return

The return value is always 0.

Description

_momFree() should always be called when a memory object is no longer needed. If this does not happen the memory object remains allocated until the end of the Xbase++ program, since no garbage collection is performed for memory objects created with _momAlloc().

Important:

The handle which is passed to _momFree() must belong to an object created with _momAlloc() and not yet released. If this is not the case, a fatal error is generated and the application terminates. When calling _momFree(), the memory object must not be locked by the thread making the call, since _momFree() would wait endlessly for the unlock. If the memory object is locked by a different thread, _momFree() waits until _momUnlock() is called by that thread and then releases the object.

Examples
/* 
Creation and release of a temporary buffer 
*/ 
#include "xppcon.h" 

MomHandle  hNew; 
BYTE      *pNew; 
LONG       size = 50; 


hNew = _momAlloc(size); 
if (hNew != MOM_NULLHANDLE) 
{ 
pNew = _momLock(hNew); 

/* 
   ... operations on the memory object 
*/ 

_momUnlock(hNew); 
_momFree(hNew); 
} 
Feedback

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.