On Thu, 16 Oct 2014, Adriaan van Os wrote:

Section 7.6 in the FreePascal Language Reference discusses automatic reference counting for COM interfaces. It details assignments to variables and temporary variables. But the section doesn't mention parameter passing. What happens when interfaces are passed to functions, procedures and methods ?

From reading Delphi documentation and by experimenting a bit, there seems to be a great difference between value and CONST parameters and between VAR and OUT parameters. I suggest to extend the manual to explain this in detail.

That will require the compiler devs explaining in detail how it works, because I haven't got a clue. AFAIK var, const and out behave the same where ref counting is concerned, with 'value' parameters being the only difference.


For example, I have an interface IMFMediaEventGenerator (from Windows MediaFoundation) with a method GetEvent

 type
   IMFMediaEventGenerator = interface( IUnknown) ...
        ....
function GetEvent( dwFlags: DWORD; out ppEvent: IMFMediaEvent): HResult; stdcall;

Now, suppose I am calling GetEvent in a loop

     theEvent := nil;
     theEventType := MEUnknown;
     theResult := S_OK;
     while ( theEventType <> MESessionClosed) and ( theResult >= S_OK) do
     begin
       theResult := theSession.GetEvent( 0, theEvent);
        ...

Now, it seems (correct me if I am wrong) that theEvent doesn't need to be manually released, because it has been declared as an OUT parameter rather than a VAR parameter. So, if this is true, this information is crucial when writing interface bindings.

Indeed.


In general, I am not a proponent of "compiler magic" because it confuses things, puts it under the table. I would certainly welcome a compiler option to NOT auto-refcount.

Talk about going against the spirit of the times :-)

Michael.
_______________________________________________
fpc-devel maillist  -  [email protected]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply via email to