The emulator should tell you whether it's in LogLoadRecord() or
SetFieldTextFromStr().
If it's LogLoadRecord() try posting the entire function and make sure it's
not returning prematurely.
If it's leaking from the field, it would be harder to see w/o the whole
file.
Matt
"David Beers" <david@...> wrote in message
news:136435@palm-dev-forum...
>
> I've got a routine that builds a big ol' string by looping through a bunch
> of records and then loads it to a field as seen below. Works great, but
> gives me a big ol' memory leak and I can't seem to see why. I assign a
> chunk of non-moveable memory to logP using MemPtrNew, then I use
MemPtrFree
> to free it after I've copied the string to the field handle. My POSE log
> shows that I have one memory leak with the contents being that big ol'
> string. I'm wondering if maybe it's the field that's leaking the memory
> somehow. It's in a modal form that I bring up using FrmPopupForm() and
> FrmReturnToForm(). Doesn't the system dispose of that memory, though?
>
> Here's the abridged version of my code, which hopefully captures what I'm
> doing wrong:
>
> static void LogLoadRecord(void)
> {
> Char *logP;
> ...
> field = GetObjectPtr(LogField);
> logP = (Char *)MemPtrNew(MAX_LOG_SIZE);
> ...
> // here I'm looping through a bunch of records and
> // doing StrCopy and StrCat to build the string.
> // POSE isn't logging any leaks of memory used here
> // as far as I can tell.
> ...
> error = SetFieldTextFromStr(field, logP);
> ...
> MemPtrFree((MemPtr) logP); // <-- The string pointed
> // to by logP is what is shown in the memory dump.
> }
>
> Here's the routine called for setting the field text.
> I use this all the time (but with error checking that
> I've left out for clarity):
>
> Err SetFieldTextFromStr(FieldPtr field, const Char *s)
> {
> MemHandle h;
>
> h = FldGetTextHandle(field);
> if (h) {
> FldSetTextHandle(field, NULL);
> err = MemHandleResize(h, StrLen(s) + 1);
> } else {
> h = MemHandleNew(StrLen(s) + 1);
> }
> StrCopy((Char *) MemHandleLock(h), s);
> MemHandleUnlock(h);
> FldSetTextHandle(field, h);
> return errNone;
> }
--
For information on using the Palm Developer Forums, or to unsubscribe, please
see http://www.palmos.com/dev/support/forums/