On the subject of leaks in DirectshowLib

Feb 3, 2009 at 11:04 AM
Hello Jeremiah,

great job on account of wpfmediakit. I've been messing with it and it looks a very nice piece of software.

I saw some of your posts on directshownet regarding a memory leak, where you ran some simple rendering tests.

I'm having the same problem here. I have a high memory requirement application and i need to overcome this issue somehow.
I have made some posts both in msdn and directshownet, if you'd care to read

http://social.msdn.microsoft.com/Forums/en-US/windowsdirectshowdevelopment/thread/a66b7e45-f990-494f-aeb0-df73727fe971

http://sourceforge.net/forum/forum.php?thread_id=2907079&forum_id=460697

but i haven't had any conclusive answers.
I was hopping you would share your findings on this matter.

Thank you,
Francisco


Feb 3, 2009 at 11:49 AM
Edited Feb 3, 2009 at 2:16 PM
Have you tried testing your graph in C++? This may help you isolate it further (If its the CLR/.NET code or a buggy filter)

In that particular case, I tested on an untouched Vista box and did not see a leak. I suspect it ended up being a nasty codec I had installed on both computers I tested.

Also, you can always do a (for testing purposes usually):

/* This will add a reference count to your COM object */
IntPtr pObj = Marshal.GetIUnknownForObject(myComObject);

/* Releases the last added reference and returns total number of refs */
int refs = Marshal.Release(pObj);

/* When refs == 0, the COM WILL be released - But this is bad practice
* as other objects (other unmanaged or even the CLR) may have a ref to
* it and may cause a crash */
refs = Marshal.Release(pObj);

-Jer
Feb 5, 2009 at 11:47 AM
Hello again Jeremiah,

thank you for your suggestion. I tried your project both on a clean Vista virtual machine and on the Vista system where i had run the previous tests.
No leak on the clean system, and on the other i detected the same leak. I'm reaching the same conclusion as you did, leaky filters.

Having come to this, do you happen to know some nice and decent codecs that do not have this problem ?

Btw, the code you suggested for releasing COM objs isn't the same as invoking this call ?

Marshall.FinalReleaseComObject(obj);


I believe this drops the COM obj reference counter to 0 and releases it..

Regards,
Francisco

Feb 5, 2009 at 12:07 PM
Edited Feb 5, 2009 at 12:08 PM
Not sure what codec to suggest. What media format are you looking to target?

Marshal.FinalReleaseComObject(...) is not the same as doing a Marshal.Release(...). FinalReleaseComObject will set the .NET RCW's reference count to 0, decrementing the COM object's reference count by 1. The actual COM object could have any amount of references. Marshal.Release(...) acts directly on the COM itself.

-Jer
Feb 5, 2009 at 1:03 PM
Well, ideally was aiming for the all kinds of media formats. That is the reason that i've installed some codec packs like K-lite,
Vista Codec pack or Xp Codec pack for the respective systems.

Due to the detected leak problems, I'm finding this idea more and more utopic, so i'm restricting it to the main media formats, .wmv (sd and hd) , .mpg, and maybe .avi.

Francisco