Search the web
Sign In
New User? Sign Up
palm-dev-forum
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Hear how Yahoo! Groups has changed the lives of others. Take me there.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
Memory leak   Message List  
Reply | Forward Message #92427 of 92429 |
Re: Memory leak

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/



Thu Aug 28, 2003 1:41 pm

mgraham@...
Send Email Send Email

Forward
Message #92427 of 92429 |
Expand Messages Author Sort by Date

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...
David Beers
david@...
Send Email
Aug 27, 2003
2:45 am

Uh, forget that part about the system disposing of the field memory in a FrmReturnToForm(). I know better, and yes, I am calling FldSetTextHandle(field, 0) on...
David Beers
david@...
Send Email
Aug 27, 2003
3:10 am

... Did you explicitly free the Field's text handle before calling FrmReturnToForm? FldSetTextHandle(field, NULL) won't (and can't) free it for you. ...
James
stickb0y@...
Send Email
Aug 27, 2003
3:43 am

The emulator should tell you whether it's in LogLoadRecord() or SetFieldTextFromStr(). If it's LogLoadRecord() try posting the entire function and make sure...
Matt Graham
mgraham@...
Send Email
Aug 29, 2003
11:06 am
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help