Hi,

I'm finishing to develop an application. Everything works fine. Yesterday I 
made some tests and I noticed that I have a huge memory leak when I try to load 
new data.

I load 6000 lines of data that I transfer in TFPObjectList. I first thought 
that the problem came from the list. I removed the list code and the problem 
doesn't disappear. So, for me, the problem come from the XML reading procedure. 
I try to search in the wiki and I didn't found thing that help me. I sure that 
the method I use to read the XML is not right one. 

Somebody can help me to correct my code?
 

The method without TFPObjectList code is below. Before reading the file the 
program use 16Mo of memory. After the execution of the 'LoadCGX' procedure the 
program use 204Mo :( .


>-------------------------------------------------------------------------------------------------------------------
procedure TCGData.LoadCGX(s:String);
var
  xdoc: TXMLDocument;                         // variable to document
  RootNode,
  node, node1, TrackpointNode : TDOMNode;    // variable to nodes
  i, j, err : Integer;
  tmpCourseName : string;
  tmpDescription : string;
  tmps, tmps1 : string;
  tmpTotalDistance,td : Double;
  tmpVersion : String;
  tmpTotalTimeSecond : integer;
  ts : String;
Begin

  DateSeparator:='/';
  ShortDateFormat:='d/m/y';

  //-- Open the XML file --
  ReadXMLFile(xDoc, s);


  //-- Search the <CourseGenerator> node --
  RootNode := xDoc.FindNode('CourseGenerator');

  if RootNode=NIL then exit; //Not found exit

  For i:=0 to (RootNode.ChildNodes.Count - 1) do begin
    Node:=RootNode.ChildNodes.Item[i];
    tmps:=Node.NodeName;

    if tmps='Version' then begin
      //-- <Version> node --
      tmpVersion:= Node.TextContent;
      //Todo: test!
    end
    else if tmps='TotalDistance' then begin
      //-- <TotalDistance> node --
      Val(Node.TextContent,tmpTotalDistance,err);
      if err<>0 then exit;
    end
    else if tmps='TotalTimeSecond' then begin
      //-- <TotalTimeSecond> node --
      Val(Node.TextContent,tmpTotalTimeSecond,err);
      if err<>0 then exit;
    end
    else if tmps='CourseName' then begin
      //-- <CourseName> node --
      tmpCourseName:= Node.TextContent;
    end
    else if tmps='Description' then begin
      //-- <Description> node --
      tmpDescription:= Node.TextContent;
    end

    else if tmps='Trackpoint' then begin
      //-- <Trackpoint> node --
      TrackpointNode := Node;

      //-- Scan level "trackpoint" --
      for j := 0 to (TrackpointNode.ChildNodes.Count - 1) do begin
        Node1:=TrackpointNode.ChildNodes.Item[j];
        tmps1:=Node1.NodeName;

        if tmps1 = 'LatitudeDegrees' then begin
          //<LatitudeDegrees>123.456</LatitudeDegrees>
          val(Node1.TextContent,td,err);
          if err<>0 then begin
            td:=0;
                //Error
          end;
        end
        else if tmps1 = 'LongitudeDegrees' then begin
          //<LongitudeDegrees>123.456</LongitudeDegrees>
          val(Node1.TextContent,td,err);
          if err<>0 then begin
            td:=0;
                //Error
          end;
        end
        else if tmps1 = 'AltitudeMeters' then begin
          //<AltitudeMeters>123.456</AltitudeMeters>
          val(Node1.TextContent,td,err);
          if err<>0 then begin
            td:=0;
                //Error
          end;
        end;
      end; //For j
      //-- Store data --
      //List.Add(TmpData);
    end;
  end; //For i


  RootNode.free;
  xDoc.Free;

End;
>-----------------------------------------------------------------------------------------------------


Thanks for your help.

Regards,

-- 
Pierre Delore 

http://datalinkwristapps.free.fr 
http://dpsite.free.fr 

--
_______________________________________________
Lazarus mailing list
[email protected]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply via email to