ContextType *context;
Then in you AppStart function add this: context=(ContextType *)MemPtrNew(sizeof(ContextType));
in AppStop add: MemPtrFree(context);
George wrote:
Hello,
Since I'm a Palm OS newbie, I need some help. I'm debugging an applicaiton using the Emulator and found out that the application sometimes gets "memory leaks" error.
Ben Combee also suggested that I should use "MemPtrNew" to decrease my stack size in my previous thread.
So, I've decided I should take a serious look at using "MemPtrNew" and "MemPtrFree" to make the application more efficient.
However, I don't know how to use them.
This is the existing code in my Pilot Main:
UInt32 PilotMain(UInt16 cmd, MemPtr cmdPBP, UInt16 launchFlags) { ContextType context; UInt16 error; context.hasGlobals = launchFlags & sysAppLaunchFlagNewGlobals;
if (cmd == sysAppLaunchCmdNormalLaunch) { globalContext = &context; error = AppStart(&context); if (error) return error; FrmGotoForm(ID_FORM_LIST); EventLoop(); AppStop(&context); return 0; } else if .... (codes snipped...)
I use ContextType to store Global variables and it's huge. That's the problem. I need to free up the resources when ContextType is not used. I just don't quite understand how to use MemPtrNew to free the memory.
Thanks for your help in advance.
George.
-- For information on using the Palm Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/
