Delphi XData Problem

Delphi XData Problem

Anonymous
Not applicable
584 Views
8 Replies
Message 1 of 9

Delphi XData Problem

Anonymous
Not applicable
I am having a problem with a Delphi function that I am using to proccess any string
values that are in the xdata that is attached to the entity. There appears to be a memory leak from
using the OleVariants. It appears as though the leak is caused by SysString from the
resource SysAllocString from oleauto.dll. I call this function thousands of time,
so eventually I get an Out Of Memory error and have to close AutoCAD in order to free the memory.

Does anyone know how I can resolve this leak, or how I can free the memory that is
being lost. Anyones help or suggestions would be greatly appreciated.

Thanks in advance, Kevin


function ReadEntityXData(const Entity: IAcadEntity): Boolean;
var
> i : Integer;
> GpCodes: OleVariant;
> GpValues: OleVariant;
> LowBoundIndex, HighBoundIndex: Integer;
> MyXValue: WideString;
begin
> Result := False;

> // make sure there is extended data
> Entity.GetXData(CDS_3D_ACAD, GpCodes, GpValues);
> try
>>> if not VarIsEmpty(GpCodes) then
>>> begin
>>>>> // get the dimensions of the XData arrays (both arrays are same size)
>>>>> LowBoundIndex := varArrayLowBound(GpCodes, 1);
>>>>> HighBoundIndex := varArrayHighBound(GpCodes, 1);
>>>>> try
>>>>>>>> for i := LowBoundIndex to HighBoundIndex do
>>>>>>>> begin
>>>>>>>>>> // to compare an olevariant the variant must be a string or an
>>>>>>>>>> // exception will be triggered so check to see if MyValue is a string.
>>>>>>>>>> if VarIsStr(GpValues) then
>>>>>>>>>> begin
>>>>>>>>>>>> MyXValue := GpValues;
>>>>>>>>>>>> if ProcessStringValue(MyXValue) then
>>>>>>>>>>>> begin
>>>>>>>>>>>>>> // do something with MyXValue
>>>>>>>>>>>> end;
>>>>>>>>>> end;
>>>>>>>> end;
>>>>>>>> Result := True;
>>>>> except
>>>>>>>> On E:Exception do
>>>>>>>> {Raise Exception}
>>>>> end;
>>> end;
> finally
>>> VarClear(GpCodes);
>>> VarClear(GpValues);
> end;
end;
0 Likes
585 Views
8 Replies
Replies (8)
Message 2 of 9

Anonymous
Not applicable
What release of Delphi is this?

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006
http://www.acadxtabs.com

wrote in message news:4848867@discussion.autodesk.com...
I am having a problem with a Delphi function that I am using to proccess any string
values that are in the xdata that is attached to the entity. There appears to be a memory leak from
using the OleVariants. It appears as though the leak is caused by SysString from the
resource SysAllocString from oleauto.dll. I call this function thousands of time,
so eventually I get an Out Of Memory error and have to close AutoCAD in order to free the memory.

Does anyone know how I can resolve this leak, or how I can free the memory that is
being lost. Anyones help or suggestions would be greatly appreciated.

Thanks in advance, Kevin


function ReadEntityXData(const Entity: IAcadEntity): Boolean;
var
> i : Integer;
> GpCodes: OleVariant;
> GpValues: OleVariant;
> LowBoundIndex, HighBoundIndex: Integer;
> MyXValue: WideString;
begin
> Result := False;

> // make sure there is extended data
> Entity.GetXData(CDS_3D_ACAD, GpCodes, GpValues);
> try
>>> if not VarIsEmpty(GpCodes) then
>>> begin
>>>>> // get the dimensions of the XData arrays (both arrays are same size)
>>>>> LowBoundIndex := varArrayLowBound(GpCodes, 1);
>>>>> HighBoundIndex := varArrayHighBound(GpCodes, 1);
>>>>> try
>>>>>>>> for i := LowBoundIndex to HighBoundIndex do
>>>>>>>> begin
>>>>>>>>>> // to compare an olevariant the variant must be a string or an
>>>>>>>>>> // exception will be triggered so check to see if MyValue is a string.
>>>>>>>>>> if VarIsStr(GpValues) then
>>>>>>>>>> begin
>>>>>>>>>>>> MyXValue := GpValues;
>>>>>>>>>>>> if ProcessStringValue(MyXValue) then
>>>>>>>>>>>> begin
>>>>>>>>>>>>>> // do something with MyXValue
>>>>>>>>>>>> end;
>>>>>>>>>> end;
>>>>>>>> end;
>>>>>>>> Result := True;
>>>>> except
>>>>>>>> On E:Exception do
>>>>>>>> {Raise Exception}
>>>>> end;
>>> end;
> finally
>>> VarClear(GpCodes);
>>> VarClear(GpValues);
> end;
end;
0 Likes
Message 3 of 9

Anonymous
Not applicable
We use this application for AutoCAD 2000, 2000i, 2002 and 2004. I know the problem exists on the AutoCAD 2000i, and 2002 versions. I am not sure if it exists on the 2004 version. Thanks again, Kevin
0 Likes
Message 4 of 9

Anonymous
Not applicable
I just did some more testing and found that this problem does not occur with the 2004 or 2005 release.

Thanks again, Kevin
0 Likes
Message 5 of 9

Anonymous
Not applicable
I was talking about the version of Delphi, not AutoCAD.

PS: You should never have to call VarClear on any
OleVariant. The runtime takes care of that for you.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006
http://www.acadxtabs.com

wrote in message news:4850108@discussion.autodesk.com...
We use this application for AutoCAD 2000, 2000i, 2002 and 2004. I know the problem exists on the AutoCAD 2000i, and 2002
versions. I am not sure if it exists on the 2004 version. Thanks again, Kevin
0 Likes
Message 6 of 9

Anonymous
Not applicable
Sorry about that. I am using Delphi 6.0 Build 6.240 Update Pack 2. I wasn't really sure if I needed the varClear, I was just trying different things to try and clear the memory. I wasn't very successful.

Thanks again Tony,
Kevin
0 Likes
Message 7 of 9

Anonymous
Not applicable
I am also having this problem. I am using Delphi 6 and I duplicated this "leak" with AutoCAD versions 2002 through 2006.

The problem lies with calls to this method:

IAcadXRecord.SetXRecordData(XRecordDataType: OleVariant; XRecordDataValue: OleVariant)

Calling that method many times results in huge memory usage. My gut feeling is that this is something to do with AutoCAD tracking undo, but when the drawing is saved and closed the memory still isn't released. The memory isn't released until AutoCAD is closed.

Any advice?
0 Likes
Message 8 of 9

Anonymous
Not applicable
Have you tried calling VarClear() on the OleVariants ?

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

wrote in message news:5134849@discussion.autodesk.com...
I am also having this problem. I am using Delphi 6 and I duplicated this "leak" with AutoCAD versions 2002 through 2006.

The problem lies with calls to this method:

IAcadXRecord.SetXRecordData(XRecordDataType: OleVariant; XRecordDataValue: OleVariant)

Calling that method many times results in huge memory usage. My gut feeling is that this is something to do with AutoCAD tracking undo, but when the drawing is saved and closed the memory still isn't released. The memory isn't released until AutoCAD is closed.

Any advice?
0 Likes
Message 9 of 9

Anonymous
Not applicable
I have tried with and without VarClear. This makes no difference unfortunately.

I can only see two possibilities as to why this occurs...

1. AutoCAD must keeps track of each call to SetXRecordData in the undo log. This would explain where all the memory is going, but I don't understand why the memory would still be in use after the drawing is closed. The memory is only released when I close that instance of AutoCAD.

2. There is a memory leak bug in SetXRecordData. Perhaps AutoCAD is creating its own copy of the OleVariants passed in the SetXRecordData function.
0 Likes