Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2009-04

Interface reference counting

3 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Felipe Monteiro de Carvalho

Hello,

Just to be sure, when using an interface from COM, can I just ignore it and the compiler will release it when it's scope ends, or do I need to manually set the variable to nil?

var
  d3d: IDirect3D9 = nil; // Direct3D interface
begin
  // create the Direct3D interface
  d3d := Direct3DCreate9(D3D_SDK_VERSION);

  // ... use the interface here

  d3d := nil; // necessary or not?
end;

thanks,

Felipe Monteiro de Carvalho
Graeme Geldenhuys
to Felipe Monteiro de Carvalho
Felipe Monteiro de Carvalho wrote 5 lines
Hello, Just to be sure, when using an interface from COM, can I just ignore it and the compiler will release it when it's scope ends, or do I need to manually set the variable to nil?

When it goes out of scope it gets freed. But I do vaguely remember something in the lines of you are not guaranteed when it gets freed. But with my testing it gets freed pretty quickly.

I use interfaces for logging (entering & exiting procedures) and for reseting the mouse cursor when a method exits.

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/