actually i am using late-binding in delphi, and i need to know wich is the proper way to work with it.
My principal concern is about how I handle the memory used by these objects, I must free the memory?
check this sample code
var
chEaten: Integer;
BindCtx: IBindCtx;
Moniker: IMoniker;
MyObject:: IDispatch;
begin
try
OleCheck(CreateBindCtx(0, bindCtx));
OleCheck(MkParseDisplayName(BindCtx, StringToOleStr('oleobject.class'), chEaten, Moniker));
OleCheck(Moniker.BindToObject(BindCtx, nil, IDispatch, MyObject));
MyObject.Metod1();
MyObject.Metod2();
finally
MyObject:=nil,// is this necesary?
end;
end;
would be helpful if someone explain briefly how is handled the memory in this type of objects.
thanks in advance.
COM Interface objects in Delphi are automatically managed by the compiler. It inserts hidden calls to AddRef
and Release
at the appropriate places, and your interfaces will automatically have their Release
methods called when they go out of scope. So no, you don't have to nil out the reference.