I have a memory leak when i read a lob field on oracle
To fix the leak, I have add
Code: Select all
ReadStream.Free;
at the end of the procedure
Moderators: gto, cipto_kh, EgonHugeist, mdaems
Code: Select all
ReadStream.Free;
Code: Select all
procedure TZOracleBlob.ReadBlob;
var
Status: Integer;
Buffer: array[0..1024] of Char;
ReadNum, Offset: ub4;
ReadStream: TMemoryStream;
Connection: IZOracleConnection;
begin
if not Updated and (FLobLocator <> nil)
and (BlobData = nil) and (not FTemporary) then
begin
Connection := FHandle as IZOracleConnection;
{ Opens a large object or file for read. }
Status := FPlainDriver.LobOpen(Connection.GetContextHandle,
Connection.GetErrorHandle, FLobLocator, OCI_LOB_READONLY);
CheckOracleError(FPlainDriver, Connection.GetErrorHandle,
Status, lcOther, 'Open Large Object');
{ Reads data in chunks. }
ReadStream := TMemoryStream.Create;
Offset := 0;
repeat
ReadNum := 1024;
Status := FPlainDriver.LobRead(Connection.GetContextHandle,
Connection.GetErrorHandle, FLobLocator, ReadNum, Offset + 1,
@Buffer, 1024, nil, nil, 0, SQLCS_IMPLICIT);
CheckOracleError(FPlainDriver, Connection.GetErrorHandle,
Status, lcOther, 'Read Large Object');
if ReadNum > 0 then
begin
ReadStream.SetSize(ReadStream.Size + ReadNum);
ReadStream.Write(Buffer, ReadNum);
Inc(Offset, 1024);
end;
until ReadNum < 1024;
{ Closes large object or file. }
Status := FPlainDriver.LobClose(Connection.GetContextHandle,
Connection.GetErrorHandle, FLobLocator);
CheckOracleError(FPlainDriver, Connection.GetErrorHandle,
Status, lcOther, 'Close Large Object');
{ Assigns a retrieved data stream. }
ReadStream.Position := 0;
SetStream(ReadStream);
ReadStream.Free; // <---Here
end;
end;