When we are using Xmotif routines such as XmTextGetString, XmTextGetSelection, which return a character pointer, these routines allocate storage for the returned string. This allocated memory should be freed by the programmer using XtFree (). e.g. string getText( ) { #ifdef _TRACELOG traceLog(eDebug,”Enetered getText () “); #endif string strText; char* pchText = NULL: pchText = XmTextGetString (TextWidget); if (pchText) { strText = pchText; XtFree (pchText); #ifdef _TRACELOG traceLog(eDebug,”Got the getText ():[%s] “, “strText.c_str () ); #endif } #ifdef _TRACELOG traceLog(eDebug,”Returning from getText () “); #endif return strText; } |
Use XtFree( ) routine to free the memory allocated by the Xmotif routines which return a character pointer. |
Thursday, July 31, 2008
When to use XtFree () ?
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment