--- In [EMAIL PROTECTED], Robert Purcell <[EMAIL PROTECTED]> wrote: > Hi Everyone, > > I know there's been some discussion lately about using POSE 3.4 > to detect memory leaks. Can anyone provide more detailed (step-by-step) > instructions on how to decipher these log files to hunt down the > code that's causing the memory leak? > <SNIP/> >
Understanding the logfile for memory leaks should be pretty easy - assuming you have DebugSymbols turned on (in CodeWarrior it's under 68k processor - Generate MacsBug Debug Symbols). If you don't, you'll see lots of 'unknown' function names. Anyway, I'm guessing you have this turned on. Well... actually I ran Blox on the emulator and got the following output, which shows that even the released version has debug info in it. ---------- 429.969: === WARNING: Blox (1.0) just read from memory location 0x00004743, which is in an unlocked chunk of memory. An "unlocked chunk of memory" is one that has been allocated with MemHandleNew but that has not been locked with MemHandleLock. Such an access usually means that an application allocated a buffer with MemHandleNew, locked it with MemHandleLock, unlocked it with MemHandleUnlock, and then used the pointer that was returned by MemHandleLock. 429.969: === WARNING: ********************************************************************** ---------- There's a whole bunch of these to start with, occurring during app startup. They're bugs that should probably be fixed, but not what we're here to look at right now. Anyway, then we get to the memory leak: ---------- ======================================================== 432.242: WARNING: Memory Leaks 432.242: WARNING: ======================================================== 432.242: WARNING: Begin Memory Leak Dump 432.242: WARNING: ======================================================== 432.242: Relocatable chunk leaked at 0x00004734, size = 41 432.242: Chunk allocated by: 432.242: AppStart 432.242: StarterPalmMain 432.242: PilotMain 432.242: __Startup__ 432.242: Chunk contents: 432.242: 50 61 6C 6D 20 4F 53 20 45 6D 75 6C 61 74 6F 72 Palm OS Emulator 432.242: 00 04 01 A6 00 04 1A 26 00 00 00 06 00 00 00 00 .......&........ 432.242: 00 00 00 00 80 03 70 BA 00 ......p.. 432.242: WARNING: ======================================================== 432.242: WARNING: End Memory Leak Dump 432.242: WARNING: ======================================================== 432.242: === WARNING: **************************************************************************** **** 432.242: === WARNING: Found 1 memory leak for Blox (1.0). Information concerning the leak can be found in the log file. 432.242: === WARNING: **************************************************************************** **** ---------- So, the interesting bit is: ---------- 432.242: Relocatable chunk leaked at 0x00004734, size = 41 432.242: Chunk allocated by: 432.242: AppStart 432.242: StarterPalmMain 432.242: PilotMain 432.242: __Startup__ ---------- This tell us that somewhere in AppStart() you allocated a Relocatable chunk (A relocatable chunk is a MemHandle (non-relocatable chunk would be a MemPtr)). This MemHandle was then never released anywhere in your code. The stack trace also tells you that the function that called AppStart() was StarterPalmMain() and so on. As it was allocated in AppStart(), it probably figures that it should be deallocated in AppStop(). So have a look in the AppStart() and find all the MemHandleNew() functions you call, and then check that they're all matched by an equivalent MemHandleFree() in AppStop() (or where ever it's appropriate for you to call them). If you're getting unrelocatable chunks, you need to look for MemPtrNew() and MemPtrFree() instead. If you still can't find the problem, look for other clues. The size of the chunk is 41 bytes. Could this be a 40 byte string with a null terminator? You can see 'Palm OS Emulator' written there (in chunk contents) - that's the HotSync name of the device, does that give you any clues? The problem is in AppStart() - could it be something to do with preferences? Cheers Russell -- For information on using the Palm Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/tech/support/forums/
