Solved

DirectShow Interface releasing

Posted on 2004-04-25
2
470 Views
Last Modified: 2012-08-13
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
Comment
Question by:BlueAlien
2 Comments
 
LVL 26

Accepted Solution

by:
Russell Libby earned 125 total points
ID: 10913471

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
 

Author Comment

by:BlueAlien
ID: 10917518
Thanks.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now