Thanks for all the replies!
I set that trigger label on init, which does not require freeing of memory,
and the error occurred when trying to free the label text that I set on
init.

I found a workaround for this, thanks to Miro Dadoun.  Do not use
CtlSetLable but rather FrmCopyLabel.  You will have to hide the object
first, then show it after the copy.  Note that it will copy memory
regardless of how big the label is, so be careful not to overrun.

> OK, here's what it looks like to me:
>
> This is a trigger label. That means it's probably got a pointer into the
> selected value of the associated list that's currently selected, *not* a
> single chunk of allocated memory for just the label. So, you should not
free
> the initial label buffer. Since you're going to be replacing it with one
of
> your own, you've correctly determined that you'll be leaking memory if you
> don't free the new chunk you've set. I suggest something like this:
>
> SetTriggerLable() {
> static char *myChunk = NULL;
> FormPtr formP;
>       ControlPtr serialP;
>       char *oldTextP, *newTextP;
>
> formP = FrmGetFormPtr(SyncPrefsForm);
>       serialP = FrmGetObjectPtr(formP,  FrmGetObjectIndex(formP,
>       SyncPrefsSerialNumberSelTrigger));
>
>       oldTextP = CtlGetLabel(serialP);
>       if (myChunk == oldTextP)
>          MemPtrFree(oldTextP);  // only free it if it was the one I
> allocated
>
>       myChunk = newTextP = MemPtrNew(whatever);
> // set up newTextP as desired
>       CtlSetLabel(serialP, newTextP);
> }
>
>  ==-
> John Schettino author of
> Palm OS Programming For Dummies, http://schettino.tripod.com
>
>
> -----Original Message-----
> From: Ken Glover [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, December 08, 1999 8:33 AM
> To: [EMAIL PROTECTED]
> Subject: Re: How to free Label text pointer?
>
>
> Thanks for the reply.
>
> If I don't free the CharPtr that the label has, and set a new label, I get
> memory leak.  But if I try to free it, I get "Bad chunk header" error.  Am
I
> making any sense?
>
> > I think that freeing of the handle only applies to textfields.  In my
> > code I don't free the handle for a button label.
> >
> >
> >
> > Ken Glover wrote:
> >
> > > Does anyone know what the error "MemoryMgrNew.c, Line:4240, Bad chunk
> > > header" mean?
> > > Here's some code:
> > >
> > > /* free the old label text so a new one can be assigned */
> > >
> > >   formP = FrmGetFormPtr(SyncPrefsForm);
> > >   serialP = FrmGetObjectPtr(formP,  FrmGetObjectIndex(formP,
> > > SyncPrefsSerialNumberSelTrigger));
> > >
> > >   oldTextP = CtlGetLabel(serialP);
> > >   MemPtrFree(oldTextP);  <-- error occurrs here
> > >
> > > /* end */
> > >
> > > Am I doing this right?  I am using 33EZDebug ROM on PalmV emulator.
> > > Thanks for reading this!
> > >
> > > Ken Glover
> > > Palm Programming Group
> > > Eclipse Inc.
> > > www.eclipseinc.com
> >
> >
>
>

Reply via email to