Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

DirectShow Interface releasing

Posted on 2004-04-25
2
472 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

839 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