danieleteti / delphi-orm

DORM, the "Delphi ORM"
175 stars 65 forks source link

Memory leak when using a MemoryStream field #45

Closed raelb closed 5 years ago

raelb commented 5 years ago

Hello,

For example, If I add a MemoryStream field to TCustomer, data is persisted correctly, however there is a memory leak when closing the program. I am using the sqlite adapter.

[Entity('CUSTOMERS')] TCustomer = class private FName: String; FEMail: String; FID: Integer; FCreatedAt: TDate; FADDRESS: String; FImage: TMemoryStream; procedure SetADDRESS(const Value: String); procedure SetCreatedAt(const Value: TDate); procedure SetEMail(const Value: String); procedure SetID(const Value: Integer); procedure SetName(const Value: String); public constructor Create; destructor Destroy; override; property ID: Integer read FID write SetID; property Name: String read FName write SetName; property Address: String read FADDRESS write SetADDRESS; property EMail: String read FEMail write SetEMail; [Column('CREATED_AT')] property CreatedAt: TDate read FCreatedAt write SetCreatedAt; property Image: TMemoryStream read FImage write FImage; end;

constructor TCustomer.Create; begin FImage := TMemoryStream.Create; end;

destructor TCustomer.Destroy; begin FImage.Free; inherited; end;

The leak occurs when performing an update or delete operation. I have adapted the Hello World demo to a VCL GUI, so memory leak reporting occurs. I added a image field to the db declared as BLOB. Am I doing something wrong, or is this a bug?

raelb commented 5 years ago

Attached is a sample project

HelloWorld GUI.zip

raelb commented 5 years ago

Answer: TMemoryStream should not be created in constructor. Instead set to nil, since it will be created autmatically when load a record from the database.