gerald-lindsly/mongo-delphi-driver — pull request #1 by jsbattig (2012-05-30 14:57:39+00:00)
Title: Modifications to improve design and resolve multiple memory leaks

Gerald, I have created this fork of the master branch with the goal of:

1. Modify design to make the whole package more usable. The way it's currently designed on the master branch, objects such as TBsonBinary, TBsonCodeIterator, etc. have to be managed using Delphi's standard object lifecycle management which typically follows the form:

CreateObject;
try
Do some work;
finally
FreeTheObject;
end;

For certain uses, when child objects are needed to perform some work, it tends to create very verbose code just to manage lifecycle.
Two typical approaches to improve design in Delphi are:

a. Make the master object own the child object
b. Work with interfaces, so the user of the child object doesn't need to worry about freeing the object because it will be automatically freed with it goes out of scope. (This is NOT garbage collection, the object is freed real-time, actually there's no garbage collected entities in Delphi)

2. Solve memory leaks. There were a few places internally on the code, where you were creating an object on a local scope that was never freed. This piece of code were modified to use the new design based on interfaces, so local temporary objects are created and they are freed right away when the object leaves scope

3. Made the package work on Delphi 2007. I'm planning to make it work up to Delphi 5, but had no time yet to test it out on Delphi 5.

4. I made the delphi code with the latest version of the C client, which I uploaded in RAR form with binaries included and Visual Studio solution file. I had to also fix a bug on the C implementation, which I reported to the owner of that project. There was a pretty bad memory overrun that I fix on the latest version of the driver.

In the future, I'm planning to write unit tests on DUnit to verify all functionality, but I had no time yet. I did all tests with some throw away tests to check a specific problem I want to get solved which implies moving massive amounts of data in binary form.