Skip to content

Instantly share code, notes, and snippets.

@stijnsanders
Last active August 29, 2015 13:58
Show Gist options
  • Save stijnsanders/9960826 to your computer and use it in GitHub Desktop.
Save stijnsanders/9960826 to your computer and use it in GitHub Desktop.
SSCCE about reference counting of TStreamAdapter's
unit SSCCE_arc;
//see also http://stackoverflow.com/questions/22846335/why-is-this-tstreamadapter-not-released
interface
procedure SSCCE_arc1;
implementation
uses bsonDoc, SysUtils, Classes, Variants, ActiveX;
procedure SSCCE_arc1;
var
d:IBSONDocument;
x:IStream;
begin
d:=BSON(['test',VarArrayOf([
BSON(['x',1]),
BSON(['x',2]),
BSON(['x',3])
])]);
{
(d as IPersistStream).Save(
TStreamAdapter.Create(
TFileStream.Create('test.bson',fmCreate),soOwned),true);
(d as IPersistStream).Load(
TStreamAdapter.Create(
TFileStream.Create('test.bson',fmOpenRead),soOwned));
}
x:=
TStreamAdapter.Create(
TFileStream.Create('test.bson',fmCreate),soOwned);
(d as IPersistStream).Save(x,true);
x:=nil;
x:=TStreamAdapter.Create(
TFileStream.Create('test.bson',fmOpenRead),soOwned);
(d as IPersistStream).Load(x);
x:=nil;
end;
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment