[Lazarus] heaptrc - Is it even worth using?

Sergei Gorelkin sergei_gorelkin at mail.ru
Mon Oct 5 18:16:10 CEST 2009


Lee Jenkins wrote:

> 
> Definitely related to TXMLDocument.  Apparently, it is either a complete 
> mess and fraught with memory leaks or am misunderstanding how to use 
> it.  Although, its not the first XML API I've used.
> 
> Once again, its back to Delphi I go :-(
> 
Your trouble looks like issue 13605, which was fixed in the meantime.
One way out is to update the FPC; if that's not possible, you might want 
to change your code to look like this:


   lRegItem := lRegs.FirstChild;
   while Assigned(lRegItem) do
     begin
       if lRegItem.nodeType = ELEMENT_NODE then
       begin
{1}     lClassName := TDOMElement(lRegItem).GetAttribute('classname');
         lDataTable := ...
         lObjType := ...
         lObjReg := gMapppings.RegisterMapping(lClassName, lDataTable, 
lObjType);
         with lObjReg do
         begin
           lNode := lRegItem.FirstChild;
           while Assigned(lNode) do
             begin
               if lNode.nodeType = ELEMENT_NODE tnen
               begin
                 lpK := ...
                 lPropName := ...
                 lColName := ...
                 lValType := ...

               //dtInteger, dtFloat, dtString, dtDateTime, dtBookean, 
dtBinary)
                 lObjReg.RegisterProperty(lPropName, lColName,
                   TFlexDataType(Integer(gDataTypeStrToInt(lValType))), 
lPK);
               end;  // if lNode.nodeType
               lNode := lNode.NextSibling;
             end;  // while
         end;  // with lObjReg
      end;     // if lRegItem.nodeType
      lRegItem := lRegItem.nextSibling;
    end;       // while

Note that the change marked as {1} is not related to the problem, it 
just shows how to get the attribute value in a more short way.

Regards,
Sergei






More information about the Lazarus mailing list