Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 477
  • Last Modified:

DirectShow Interface releasing

Hi.

I have a probblem releasing the DirectShow Interfaces previously allocated. Example:

var
  gb: IGraphBuilder;
  mc: IMediaControl;

...
CoCreateInstance(CLSID_FilterGraph, nil, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, gb);
gb.QueryInterface(IID_IMediaControl, mc);
...
if(mc<>nil) then
begin
  mc._Release;
  mc:=nil;
end;
if(gb<>nil) then
begin
  gb._Release;
  gb:=nil;
end;

I always receive a Access violation. Do you know what may be causing this?

PS:
I'm using the DirectShow header from www.progdigy.com.
Thanks.
0
BlueAlien
Asked:
BlueAlien
1 Solution
 
Russell LibbySoftware Engineer, Advisory Commented:

Delphi's interface pointers are considered smart pointers, meaning this: versions since Delphi3 provide automatic management of interface variables, so calling

mc:=nil;

will handle calling the interface Release for you, thus you should *never* (almost never) call Release yourself. As well, if the variable is local in scope, the interface will be released for you at the end of the function/procedure if the variable is non nil. So, as a general rule of thumb, you will almost never need to call AddRef/Release on interface pointers. (The only exceptions would be in rare cases where the interface is cast and held as a generic pointer type.)

Regards,
Russell
0
 
BlueAlienAuthor Commented:
Thanks.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now