Board index » delphi » Delphi 7 Attachments demo - little question

D7 Attachments demo - little question


2007-12-10 06:49:25 AM
delphi183
Hi,
I noticed that on the server side program, in the unit
DBAttachmentImpl.pas, it does not explicitly free the
stream "GraphStream" that provides the source for
the TSOAPAttachment Result of GetSpeciesInfo.
An excerpt of the code from line 133 is below.
GraphStream := TMemoryStream.Create;
try
Result := TSoapAttachment.Create;
TBlobField(DS.FieldByName(SGraphics)).SaveToStream(GraphStream);
Result.SetSourceStream(GraphStream, soReference);
LoadSpeciesInfo(SpeciesInfo, DS);
except
on E: Exception do
begin
if Assigned(Result) then Result.Free;
DS.Close;
Result := Nil;
GraphStream.Free;
DBDemoError(E.Message);
end;
GraphStream is only being freed explicitly on an Exception.
My question is: In order for the TSOAPAttachment to free
GraphStream when it has finished with it, shouldn't "soOwned"
have been used? ie.
Result.SetSourceStream(GraphStream, soOwned);
Thanks,
Ian.
 
 

Re:D7 Attachments demo - little question

Hello Ian,
I don't have the sample handy but your assessment looks right. I don't
particularly like code that has such involved exception block. I don't
recall what style of server that sample uses (CGI, WebAppDebug, ISAPI??) but
I suspect that (if it is CGI or WebAppDe{*word*81}) building it with one of the
memory trackers (such as FastMM) would reveal the leak. I am making a note to
investigate this as soon as time allows. I will relay my findings.
Cheers,
Bruneau.