gerald-lindsly / mongo-delphi-driver

MongoDB Driver for Delphi
Apache License 2.0
47 stars 26 forks source link

Modifications to improve design and resolve multiple memory leaks #1

Closed jsbattig closed 10 years ago

jsbattig commented 12 years ago

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)

  1. 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
  2. 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.
  3. 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.
  4. Added comprehensive DUnit tests for MongoDb and MongoBson units. Placeholder for GridFS unit. Compiles on Delphi 5, Delphi 2007 and Delphi XE2