>     dbID = DmFindDatabase(0, "SharedLibraryXYZ");
>     dbRef = DmOpenDatabase(0, dbID, dmModeReadOnly);
>     codeRes = DmGet1Resource('code', 1);
>     retval = MemHandleLock(codeRes);
>     DmReleaseResource(codeRes);
>     DmCloseDatabase(dbRef);
>     ...
>     i = theLibraryFunction("abc", 5);
>...
>4) I am a novice Palm programmer. I made the decision to go ahead and
>release the resource and close the database immediately after locking down
>the code segment; it saves a lot of tracking and housekeeping when my
>application exits. So far there have been no ill effects from doing so, but
>the gurus from Palm may well come up with a scenario in which this is a BAD
>THING. If so, I'd love to hear about it so I can mend my evil ways.


I spotted the problem in your code and was happy to see you realized it was
dangerous.  The reason it is dangerous is that the code block isn't locked
in memory, which means it can be moved around at any time if the system
needs to compact the heaps in order to allocate memory.  This'd mean you
could be jumping to a random spot in the storage heap, say the middle of a
Datebook record or something, which would have, well, interesting effects
:-)

You probably wouldn't see a crash if you had lots of free space and a clean
device (which is nearly always the case in the Palm OS Emulator for
example) but this is just a timebomb waiting to go off when the system
compacts memory.

You really need to keep that resource locked.  If you don't want to bother
cleaning up properly when you quit, that's ok: just don't close the
database and it'll be done for you when you quit.  But it isn't that hard
to do, and having a database open needlessly just wastes memory and slows
things down.

-David Fedor
Palm Developer Support

-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/

Reply via email to