Well....

True, you are creating your list dynamically, but I (for one) would hardly
call it a dynamic list.

To answer your question -- if you create the list (LstNewList) on form open,
I would trash your memory on form close.  Don't forget to check whether or
not you ever actually allocated the memory, though.

But I would advise you to actually use a dynamic list.  That is to say,
NEVER allocate the bunch of MemPtrNew and Char** stuff.  How do you manage
the list, then, you ask?  That is what custom draw routines are for, I
answer.  The custom draw routine can look in your database and draw
appropriate stuff.  Then the only memory you need to allocate dynamically is
for the popup trigger (assuming you are using a trigger to manage the list).
You can trash that memory at form close time as recommended above.  This
approach has about the same amount of code but uses significantly less
memory.  Try it, you'll like it!

-bob mckenzie

-----Original Message-----
From: Ryan Parlee [mailto:[EMAIL PROTECTED]]
Sent: Monday, October 22, 2001 10:40 AM
To: Palm Developer Forum
Subject: Memory leaks with dynamic lists


I'm using dynamic lists in my app, with the data coming from a database.

I create the list here--

case frmOpenEvent:
    LstNewList(&form, 5000, 10, 10, ....trgEntryClient);
    ...

then when I get a ctlSelect--

case ctlSelectEvent:
    switch(event->data.ctlSelect.controlID) {
        case trgEntryClient:
            handled = trgEntryClient_Select(event, 5000);
            break;
    ...



Okay, so now in my trgEntryClient_Select() function, I create a list
(Char**) by reading the database and doing a bunch of MemPtrNew() calls.
This gives me an array of pointers to strings, which is exactly what
LstSetListChoices() needs.  I then reposition the popup list near the
trigger control and continue...


The problem is that all of those MemPtrNew() functions need to have matching
MemPtrFree() calls.  But when do I do this?  I need to the memory to be
locked long enough for the user to select an item in the list and then for
that item to be populated in the trigger control.  When should I deallocate
the memory?

Thanks, Ryan





-- 
For information on using the Palm Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/tech/support/forums/

-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/

Reply via email to