At 7:21 -0700 6/3/03, Brian Preston wrote:
Thanks for your reply, but I'm still confused. I have
a matching MemPtrFree for each MemPtrNew, and a
matching MemHandleUnlock for each MemHandleLock, and I
have the MemPtrFree after the MemHandleUnlock. Is that
not right?

Yes, it's not right. You are mixing new/dispose calls from two different kinds of memory, movable chunks and unmovable chunks.


MemPtrFree should only be called on nonmovable chunks. But since you started with a handle, you're working with a movable chunk. To dispose of movable chunks use MemHandleFree. MemHandleLock does in fact give you a pointer, but the original memory (ref'd by the handle) remains a movable chunk (albeit a locked one).

MemHandleLock doesn't allocate any new memory. MemPtrFree should only be called on memory that was allocated with MemPtrNew.

See the table at the end of the "Memory" section in the PalmOS Companion (p. 190 in my edition) for a summary of the calls. And IIRC Neil Rhodes does a nice job of working through this stuff too. It was not easy stuff to get my brain around the first 5 times, but it finally sunk in. And it really is crucial to getting your programs to work correctly, so stay with it.

H

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

Reply via email to