"DIAMOND JEFF" <[EMAIL PROTECTED]> wrote in message
news:38141@palm-dev-forum...
>
> Serves me right - I've used nothing dynamic so far but databases, and
> sure enough, my code was robust.
>
> Now I broke down and finally used MemPtrNew and MemPtrFree, and I have a
> memory leak (underlocked chunk).
>
> I'm using Codewarrior 7 under Windows. Can anyone recommend a good way
> to find a memory leak?
>
> I tried using the Palm Debug Console, but to be honest, I can't make
> much sense out of the heap dump.
Its pretty simple once you know what everything means.
Lets say you debug when your program exits and you see the memory leak
dialog.
Now, open the console and do a hd 0.
Look through the list for memory that belongs to your program. These chunks
will usually have owner #2 and a star at the front of the line. Note that
the CW debugger on Windows reverses the labels for lock and owner -- the
first number shown is the owner.
Say you have something that looks like
start handle localID size size lck own flags
-------------------------------------------------------
*000046D4 00001B9C 00001B9D 00000C 000014 #2 #1 fM
The first thing you can tell is that the block of memory starts at 0x46D4.
So, if you do "Data/View Memory" from CW, you can enter that hex address and
see the contents of the lost chunk.
The second thing to notice is the size. Here, the chunk is 0xC bytes == 12
bytes. You can use that along with the contents to try to guess where this
memory was allocated by your program.
Here, the lock count is 1 -- that means the chunk was allocated with
MemHandleNew and is locked. If its #15, it was allocated by MemPtrNew.
Finally, the handle is 0x1B9C -- that means the MemHandle variable that goes
with this would have the value 0x80001B9C.
This last bit is useful for debugging code in the middle of a program. If
you've breaked somewhere and just have a handle that isn't locked, you can
do a "hd 0", find the handle, then use that to get the address of the chunk
that goes with the handle for viewing in the memory window. It would be
nice to automate this, but that's beyond the CW debugger for the time being.
I hope this helps... I think I'll send this reply on to Warren to add to his
FAQ.
--
Ben Combee
Veriprise Wireless <http://www.veriprise.com>
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/