域
域
Unregistered / Unconfirmed
GUEST, unregistred user!
测试中发现,每执行一次下面的过程内存占用就会多出100k左右,但从代码上我没看出哪里是元凶,请各路大侠帮忙看一下,哪里有可能导致内存泄漏?代码如下:
procedure TMainFrm.LoadDoc;
var
Stream, destream: TMemoryStream;
begin
if qry1.RecNo>0 then
begin
redt.clear;
Stream:=TMemoryStream.Create;
destream:=TMemoryStream.Create;
try
if not (qry1.FieldByName('OLE').IsNull) then
begin
if not ConPasswd then Exit;
TBlobField(qry1.FieldByName('OLE')).SaveToStream(Stream);
Stream.Position:=0;
UnCompress(stream,destream);
pgsbr1.Percent:=40;
redt.LoadFromStream(destream);
pgsbr1.Percent:=90;
end
finally
Stream.Free;
destream.Free;
end;
end;
end;
procedure UnCompress(const CompressedStream: TMemoryStream;var destream:TMemoryStream);
var
SourceStream: TDecompressionStream;
Buffer: PChar;
Count: Integer;
Begin
//从被压缩的流中读出原始流的尺寸
CompressedStream.ReadBuffer(Count, SizeOf(Count));
//根据原始流的尺寸大小为将要读入的原始流分配内存块
GetMem(Buffer, Count);
Try
SourceStream := TDecompressionStream.Create(CompressedStream);
//将被压缩的流解压缩,然后存入Buffer内存块中
SourceStream.ReadBuffer(Buffer^, Count);
destream.WriteBuffer(Buffer^, Count);
destream.Position := 0;//复位流指针
finally
FreeMem(Buffer);
end;
end;
procedure TMainFrm.LoadDoc;
var
Stream, destream: TMemoryStream;
begin
if qry1.RecNo>0 then
begin
redt.clear;
Stream:=TMemoryStream.Create;
destream:=TMemoryStream.Create;
try
if not (qry1.FieldByName('OLE').IsNull) then
begin
if not ConPasswd then Exit;
TBlobField(qry1.FieldByName('OLE')).SaveToStream(Stream);
Stream.Position:=0;
UnCompress(stream,destream);
pgsbr1.Percent:=40;
redt.LoadFromStream(destream);
pgsbr1.Percent:=90;
end
finally
Stream.Free;
destream.Free;
end;
end;
end;
procedure UnCompress(const CompressedStream: TMemoryStream;var destream:TMemoryStream);
var
SourceStream: TDecompressionStream;
Buffer: PChar;
Count: Integer;
Begin
//从被压缩的流中读出原始流的尺寸
CompressedStream.ReadBuffer(Count, SizeOf(Count));
//根据原始流的尺寸大小为将要读入的原始流分配内存块
GetMem(Buffer, Count);
Try
SourceStream := TDecompressionStream.Create(CompressedStream);
//将被压缩的流解压缩,然后存入Buffer内存块中
SourceStream.ReadBuffer(Buffer^, Count);
destream.WriteBuffer(Buffer^, Count);
destream.Position := 0;//复位流指针
finally
FreeMem(Buffer);
end;
end;