in article 34018@palm-dev-forum, Mauricio Tavares at [EMAIL PROTECTED] wrote on
2000-12-25 14:02:
>
> Here are a few easy questions I would appreciate if any of you could answer:
>
> o When you quit a Palm program, what happens to the main form? Should it
> be somehow deallocated from memory or will the OS (any version?) take care
> of it?
When you receive a frmCloseEvent, do not return true to indicate that you
have handled it. Return false, and the system handlers will close the form.
Also, it is "normal" to call FrmCloseAllForms() when quitting, after your
event loop has ended.
> o When I create a form pointer (say, for a modal dialog box) using
> FrmInitForm(), when I close the dialog box, should I deallocate it from
> memory (using FrmDeleteFrom())?
Yes, call FrmDeleteForm after a dialog box has completed (after FrmDoDialog
returns).
> What about form pointers created with FrmGetActiveForm()? I assume this later
> I should not deallocate unless I am quitting the proggie, right? =)
When you call FrmGetActiveForm, you are not allocating anything, just
getting a pointer to something that's already there. The form will be
deallocated another way (as discussed in the first question above).
> o Let's say I create a StrListPtr as follows (a bit of pseudocode):
>
> StrListPtr pStringList;
> MemPtr pTheString;
>
> pStringList = MemHandleLock(hStringList);
> pTheString = pStringList->firstString;
>
> Now, let's say that down the line I get rid of hStringList:
>
> MemHandleUnlock(hStringList);
> DmReleaseResource(hStringList);
>
> What happens to pStringList and pTheString?
MemHandleLock locks a memory chunk in place and returns a pointer to it.
While the chunk is locked, that pointer is valid. Once you call
MemHandleUnlock, the chunk may move in memory and the pointer is no longer
valid. Any pointers based on that pointer, such as pTheString, are also no
longer valid. And those pointers are even, umm, less valid after you release
the resource. Assigning pTheString to point into the resource doesn't
allocate anything nor copy the string anywhere, so pTheString is no longer
valid once the chunk is unlocked. If you want the string to stay usable
after you unlock and release the chunk, you must copy it somewhere else
before doing the MemHandleUnlock.
______________________________________________________________________
Philip D. Wasson pwasson@maned dot com
Software Engineer
Managing Editor, Inc.
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/