Reputation: 115
We have an application developed using Delphi 5 that we cannot upgrade to Delphi 6 or later for some reasons that are not important here.
Some time ago we had to implement XML processing into that application, and I decided to copy the implementation that we made for other applications using Delphi 6.
Everything went fine. I translated the Delphi 6 sources (msxml.pas, xmldoc.pas, msxmldom.pas, etc.) to Delphi 5. Minor adjustments had to be done on each file (like removing Variants uses for example). It worked, but I'm facing some problems with memory releasing.
I believe the problem is related to how Delphi 5 and Delphi 6 implements interfaces. I just copied the interfaces and their implementations from Delphi 6 to 5. Delphi is not releasing the memory properly. Debugging the code we determined that the origin of the problem is on TXMLDocument.ReleaseDoc
on XMLDoc.pas. Seems like the line FDOMDocument := nil
is not releasing the memory that it was supposed to do.
Can anybody give me some help on this? If we can't fix this we'll have to recode the whole thing using another XML library.
Upvotes: 0
Views: 797
Reputation: 115
Thanks a lot guys...
I don't know why I did, but while copying the Delphi 6 files to Delphi 5, I changed the line
Result := inherited _Release;
to
Result := 0; //inherited _Release;
on function TXMLNode._Release: Integer;
Changed it back. Tested and the Delphi 5 program started to run just like the Delphi 6...
Thanks again for your time!
Upvotes: 1
Reputation: 1007
You can check to see if fDOMDocument has additional references held elsewhere: Just before setting fDOMDocument := NIL, do
references := fDOMDocument._AddRef ;
fDOMDocument._Release ;
if "references" is greater than 1 you need to go searching for other variables holding references to the interface.
Upvotes: 1
Reputation: 21640
Double check that FDOMDocument
is actually an interface in both cases, otherwise 'FDOMDocument := nil' will do nothing but leak if it is an Object reference.
Verify also that you don't hold another reference to FDOMDocument
that would prevent ReleaseDoc to free it.
In particular, beware of circular references on Interfaces!
Upvotes: 3
Reputation: 163247
Delphi 6 releases interfaced objects the same way Delphi 5 does.
You'll need to debug to find where your Delphi 5 program goes wrong.
Start with a small test case that demonstrates that memory doesn't get freed. Run it in both versions of Delphi to confirm that the problem is only exhibited in Delphi 5.
If possible, use your Delphi 5 version of the XML library in the Delphi 6 test case, too. Otherwise, you can't be sure that you didn't introduce the problem yourself when you translated the library to Delphi 5.
Upvotes: 4