I realize this is a really novice question, so please forgive me (but that
means it should be easy to answer).

When you allocate space for a CharPtr array, like so:

CharPtr someText = new Char[20];

And then you pass that pointer to a palm function, such as:

CtlSetLabel(labelPointer, someText);

What is the proper way to avoid a memory leak?  Is the memory that was
allocated freed automatically when the form is unloaded, or do I have to
explicitly destroy it myself, as in:

delete [] someText;

If I try to destroy it myself immediately after I pass it to the function, I
get any number of errors along the lines of:

"The application has just read directly from an unallocated chunk of
memory."

It also occurs to me that I could place the code to free the memory in the
form's unloading event, but I don't really think that's the right answer
either.  I have run into a number of areas where once I pass a pointer off
to a system function, I can not safely free the memory, and I just want to
make sure that something is handling it.

-Jeff


-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palm.com/devzone/mailinglists.html

Reply via email to