Maybe, if you are using C++, this helps:
I've written some classes that encapsulate the MemHandle locking and
unlocking and work as smart pointers. I've attached them to this mail.
Regards,
Juergen
Del Ventruella schrieb:
> In my first (and only) experience, the memory leaks were issues that could
> be eliminated. Finding them seemed to involve both intuition and carefully
> implemented methodology. I could locate no emulator menu option that would
> permit me to access variable names corresponding to memory space that had
> not been properly handled. In the end I had to debug the software by simply
> using various options built into my software to determine if, when I
> abruptly closed the program to return to the main Palm screen after running
> a specific function, the number of memory leaks was zero or some finite
> number.
>
> In some screens and options, I only created one or two variables before
> saving to the database. If by closing abruptly after only entering that
> screen or using a specific function associated with it there were two memory
> leaks, I could logically connect them to the two variables associated with a
> specific data entry screen function. By this method, you can, perhaps,
> directly identify the buggy code.
>
> There is more in prior threads regarding this memory leak problem and how to
> debug it. I must admit the methods suggested were of no use to me in
> practical terms as they seemed to indicate the need to connect hexadecimal
> memory addresses to specific, variable related, memory space that had not
> been appropriately deallocated. Good luck.
>
> Just remember: If it's Palm OS development oriented, it's got to be easy.
> :-)
--
For information on using the PalmSource Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/support/forums/
#ifndef FREEHANDLEPOLICY_H
#define FREEHANDLEPOLICY_H
#include "MemoryMgr.h"
class FreeHandlePolicy{
public:
FreeHandlePolicy() {}
protected:
void FreeHandle(MemHandle h) { MemHandleFree(h); }
~FreeHandlePolicy() {}
};
#endif // FREEHANDLEPOLICY_H
#ifndef MEMORYHANDLE_H
#define MEMORYHANDLE_H
#include <MemoryMgr.h>
#include "NullHandlePolicy.h"
template<class Type, class HandleFreePolicy = NullHandlePolicy>
class MemoryHandle : public HandleFreePolicy {
public:
MemoryHandle(MemHandle h) : fH(h),
fPointer(static_cast<Type*>(MemHandleLock(h))) {}
~MemoryHandle() { MemHandleUnlock(fH); HandleFreePolicy::FreeHandle(fH); }
MemoryHandle(const MemoryHandle<Type>& other)
: fH(other.fH), fPointer(static_cast<Type*>(MemHandleLock(fH))) {}
MemoryHandle<Type>& operator=(const MemoryHandle& other)
{ MemHandleUnlock(fH); fH = other.fH; fPointer =
static_cast<Type*>(MemHandleLock(fH)); return *this; }
MemHandle getHandle() const { return fH; }
void setHandle(MemHandle newHandle)
{ MemHandleUnlock(fH); fH = newHandle; fPointer =
static_cast<Type*>(MemHandleLock(fH)); }
Type* operator->() { return fPointer; }
Type* getPtr() { return fPointer; }
private:
MemoryHandle();
MemHandle fH;
Type* fPointer;
};
#endif#ifndef NULLHANDLEPOLICY_H
#define NULLHANDLEPOLICY_H
#include "MemoryMgr.h"
class NullHandlePolicy {
public:
NullHandlePolicy();
protected:
void FreeHandle( MemHandle) { }
~NullHandlePolicy() {}
};
#endif // NULLHANDLEPOLICY_H