Are you referring to LstSetListChoices? If so, that routine tells the list where its
text strings are located, but does nothing to allocate them.
When you say "populated from database" do you mean something of the following sort:
Char** gppItems;
void PopulateList(ListPtr pList, UInt16 numChoices) {
MemHandle h;
MemPtr p;
Int32 size;
UInt16 i;
// allocate pointer memory
gppItems = MemPtrNew(numChoices * sizeof(Char*));
if (gppItems) {
MemSet(gppItems, sizeof(ppItems), 0);
// walk the db
for (i=0; i<numChoices; i++) {
h = DmQueryRecord(pDb, i);
if (h) {
size = MemHandleSize(h);
p = MemHandleLock(h);
gppItems[i] = MemPtrNew(size);
if (gppItems[i]) {
MemMove(gppItems[i], p, size);
}
MemHandleUnlock(h);
}
}
LstSetListChoices(pList, gppItems, numChoices);
}
}
which walks a db, allocates new memory, and tells the list of it? If so, you would
need a routine of the following sort:
void FreeList( UInt16 numChoices) {
UInt16 i;
if (gppItems) {
for (i=0; i<numChoices; i++) {
if (gppItems[i]) {
// free each one
MemPtrFree(gppItems[i]);
}
}
// free the dynamically allocated list of pointers
MemPtrFree(gppItems);
}
}
Note that the array of pointers, gppItems, is held in a global to insure that it will
remain valid during the lifetime of the form (it doesn't have to be dynamically
allocated as I did). Note also that you don't have to actually copy the text of each
record if you are willing to keep the records locked while the form is open. Indeed,
an alternate approach is:
Char* gppItems[kNumChoices];
void PopulateList(ListPtr pList, UInt16 numChoices) {
MemHandle h;
UInt16 i;
MemSet(gppItems, sizeof(ppItems), 0);
// walk the db
for (i=0; i<numChoices; i++) {
h = DmQueryRecord(pDb, i);
if (h) {
gppItems[i] = MemHandleLock(h);
}
}
LstSetListChoices(pList, gppItems, numChoices);
}
void FreeList( UInt16 numChoices) {
UInt16 i;
for (i=0; i<numChoices; i++) {
if (gppItems[i]) {
// unlock each one
MemPtrUnlock(gppItems[i]);
}
}
}
-bob mckenzie, palmsource pdx
-----Original Message-----
From: N [mailto:[EMAIL PROTECTED]]
Sent: Monday, October 07, 2002 3:50 PM
To: Palm Developer Forum
Subject: RE: LIST MEMEORY LEAKS
Date: Mon, 7 Oct 2002 15:04:59
--------------------------------------------------------------------------------
In API Reference page 356-357 provides details of how
dynamic list is populated.
But I cannot find any infomation anywhere about HOW to
release memory for these type of lists.
-----Original Message-----
From: N
Sent: Monday, October 07, 2002 1:20 PM
To: Palm Developer Forum
Subject: LIST MEMEORY LEAKS
*Please correct me if you find any of my assumption
wrong.
I have this test application contains two forms. Both
form contains a list which is populated from database
on FrmOpenEvent. I have a function which allocates
memory and populates data and Callback function to
draw list.
When I exit my application it gives me one memory
leak, no matter how many times I toggle between these
two forms. So I reached to a conclusion that
FrmCloseEvent automatically realse the memory of a
form if you are jumping to second form. I don't have
any cleanup code on form close event.
If I write code on FrmCloseEvent
MemPtrFree(ListData) ;
handled = false ;
Application crashes when I try to jump to second form,
if I exit application from first form I get no memory
leaks and any crashes.
Please help me understand this issue and suggest any
solution.
Thanks in advance.
__________________________________________________
Do you Yahoo!?
Faith Hill - Exclusive Performances, Videos & More
http://faith.yahoo.com
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/support/forums/
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/support/forums/