> I've reduced the program down to as simple a program as I think I can > get away with: just a form with nothing on it except the title and the > only events that the form event handler deals with is "frmOpenEvent" (in > which case it calls 'FrmDrawForm()' to draw the empty form) and > "appStopEvent" (call 'FrmDeleteForm()'). I still get 2 memory leaks. > I'm about ready to pull out what little hair I've got left.
You shouldn't call FrmDeleteForm() in response to appStopEvent. (Maybe that's what the sample does; if so then IMHO the sample is at least out of date and possibly just wrong). The way it's designed to work is that your event loop terminates when it sees appStopEvent. At some point after that, the app's final cleanup code calls FrmCloseAllForms(). That dispatches frmCloseEvent events to all open forms. That event ultimately reaches either the form's event handler function, or the default FrmHandleEvent(). If you look at the OS 4.0 source (or 3.0 or 3.5 will give similar insight), you'll notice that FrmHandleEvent() actually does several things in response to frmCloseEvent. Two of those things are a call to FrmEraseForm(), and later a call to FrmDeleteForm(). FrmEraseForm() is responsible for, among other things, restoring _and freeing_ the saveBehind bits from under the form. The stack trace you gave seems to be exactly this. But even if your form doesn't have the saveBehind attribute, the point is that FrmDeleteForm() is only a very small part of what would normally happen when closing a form. Also, if you explicitly handle frmCloseEvent, then I recommend either explicitly calling FrmHandleEvent() to allow it to do the proper cleanup, or return false to allow the OS to call FrmHandleEvent() to do the proper cleanup. This is important so that as new features get added to the OS, your cleanup code path will still include everything it needs to. For example, OS 4.0 added the Attention Manager, which requires additional cleanup work in response to frmCloseEvent. > ================================8<--------------------------------- > 0.000: Relocatable chunk leaked at 0x00002796, size = 40 > 0.000: Chunk allocated by: > 0.000: WinCreateBitmapWindow > 0.000: WinCreateOffscreenWindow > 0.000: WinSaveBits > 0.000: FrmDrawForm > 0.000: <Unknown @ 0x00052358> > 0.000: PrvSendEventToForm > 0.000: FrmDispatchEvent > 0.000: <Unknown @ 0x0005244C> > 0.000: <Unknown @ 0x00052482> > 0.000: <Unknown @ 0x00052286> > ================================8<--------------------------------- > 0.000: Non-relocatable chunk leaked at 0x00034FF4, size = 3380 > 0.000: Chunk allocated by: > 0.000: BmpCreate > 0.000: WinCreateOffscreenWindow > 0.000: WinSaveBits > 0.000: FrmDrawForm > 0.000: <Unknown @ 0x00052358> > 0.000: PrvSendEventToForm > 0.000: FrmDispatchEvent > 0.000: <Unknown @ 0x0005244C> > 0.000: <Unknown @ 0x00052482> > 0.000: <Unknown @ 0x00052286> > ================================8<--------------------------------- -- For information on using the Palm Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/
