I have a question regarding pointers and handles...  When exiting my application, CW 
says that I have 1 memory leak.  I was
under the impression that for each handle I have, I should free it, and for each 
pointer, I should free it when I am done with
it.  The code below is what is giving me the problem.  It only happens if I have 
records in the DB, i.e. the code makes it to
the 'for loop'.

I put the MemPtrFree(itemList); and MemHandleFree(recordH); in the code (see the 
bottom of this email) but when I do, I get a
fatal error.  My question is, where should I be doing the cleanup for this handle?

Thanks,
Ed.

void frmTypesInitForm() {
    FormPtr        frmP = FrmGetActiveForm();
    ListType       *lstP;
    UInt16         theCategory = dmAllCategories;
    UInt16         totalItems, i;
    UInt16         recordNum = 0;
    UInt16         pos = 9;
    MemHandle      recordH;
    Char           **itemList;

    // List box
    lstP = (ListType *) FrmGetObjectPtr(frmP, FrmGetObjectIndex(frmP, frmTypesList));

    // Get number of records in database
    if(gSRCatDB != NULL){

       totalItems = DmNumRecordsInCategory(gSRCatDB, theCategory);
       itemList = (Char **) MemPtrNew(totalItems * 16);

        // Code to visit every record:
        for (i = 0; i < totalItems; i++) {
            recordH = DmQueryNextInCategory (gSRCatDB, &pos, theCategory);

            if (recordH) {
               skelSRCatDBType * p = (skelSRCatDBType *) MemHandleLock(recordH);
               itemList[i] = (char *) &(p->ExType);

               MemHandleUnlock(recordH);
               pos++;
            }
       }

       LstSetListChoices(lstP, itemList, totalItems);
       //MemPtrFree(itemList);
       //MemHandleFree(recordH);
    }
}



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

Reply via email to