I convert a lot of text with mdlText_getElementDescr:
status=mdlText_getElementDescr (&edPText, &edP->el.text_2d, NULL);
if (status == SUCCESS)
{
// do nothing mdlElmdscr_freeAll(&edPText);
}
Used Memory grows over the time. Is there really a bug in this function? How to free the Memory? Is there any Workaround?
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
Unknown said:mdlText_getElementDescr (&edPText, &edP->el.text_2d, NULL)
I see that you frree edPText, but what about edP? If edP is a text element, why not use that descriptor?
Regards, Jon Summers LA Solutions
Unknown said:of course edP is freed
Where does edP originate? If it's from a model scan, then you should not free it.
Unknown said:It is from model scan.But why it should not freed?
Whether it should or should not be freed depends on how you write your scan. If you explicitly read the element descriptor in your scan code, then the descriptor is yours to free. If, on the other hand, you use an element descriptor provided by a scan callback function, then the descriptor is not yours to free.
Example (from MDL help) of reading an element descriptor yourself:
do { scanSize = sizeof (scanBuf) / sizeof (short); scanStatus = mdlScanCriteria_scan (oscP,scanBuf,&scanSize,&scanPosition); for (lP = scanBuf; lP < scanBuf + scanSize / 2; ++lP) { MSElementDescr *edP; if (mdlElmdscr_readToMaster (&edP, *lP, mdlModelRef_getActive(), FALSE, NULL)) { ... mdlElmdscr_freeAll (&edP); } } } while (scanStatus == BUFF_FULL);
Example of scan callback:
// In your scan function mdlScanCriteria_setElmDscrCallback (pScanCrit, (PFScanElemDscrCallback)writeWorkFunc, (void*)cpArgms); mdlScanCriteria_scan (pScanCrit, NULL, NULL,NULL);
The scan callback function:
int writeWorkFunc ( MSElementDescr* edP, /* => This descriptor is not yours (should be MSElementDescr const* edP) */ void* args, ScanCriteria* scP ) { MSElementDescr *newDescrP = NULL; /* Here's how to obtain a descriptor that belongs to you */ mdlElmdscr_duplicate (&newDescrP,edP); /* Do something with duplicate descriptor */ mdlElmdscr_freeAll (&newDescrP); /* But don't free edP */ return SUCCESS; }