COM server won't let go of reference

This forum is for reporting bugs in MediaMonkey for Windows 4. Note that version 4 is no longer actively maintained as it has been replaced by version 5.

Moderator: Gurus

darchangel
Posts: 26
Joined: Wed Nov 30, 2005 11:23 pm

COM server won't let go of reference

Post by darchangel »

In scripting, when doing this to get a reference to: MediaMonkey

Code: Select all

SongsDB.SDBApplicationClass SDB = new SongsDB.SDBApplicationClass();
you can never undo it. Regardless of which application is shut down first, MediaMonkey throws a COM Server Warning. There's no way to detach, even after the calling app is shut down.
Steegy
Posts: 3452
Joined: Sat Nov 05, 2005 7:17 pm

Post by Steegy »

This might not be a MM specific problem.
However, is it really necessary that MediaMonkey shows the "COM Server Warning"? Can't it just close?
Extensions: ExternalTools, ExtractFields, SongPreviewer, LinkedTracks, CleanImport, and some other scripts (Need Help with Addons > List of All Scripts).
darchangel
Posts: 26
Joined: Wed Nov 30, 2005 11:23 pm

Post by darchangel »

Steegy wrote:is it really necessary that MediaMonkey shows the "COM Server Warning"? Can't it just close?
I definitely like that idea best. However, barring that, there still needs to be some way to code your way out of this mess.
Peke
Posts: 17457
Joined: Tue Jun 10, 2003 7:21 pm
Location: Earth
Contact:

Post by Peke »

Like I said I'm not a .net coder But when I wanna Ensure that No COM Connection is left I do this in Delphi;

Code: Select all

SDB := CreateOleObject('SongsDB.SDBApplication');
// Free variable to avoid COM Warning
SDB := Nil;
Best regards,
Peke
MediaMonkey Team lead QA/Tech Support guru
Admin of Free MediaMonkey addon Site HappyMonkeying
Image
Image
Image
How to attach PICTURE/SCREENSHOTS to forum posts
Steegy
Posts: 3452
Joined: Sat Nov 05, 2005 7:17 pm

Post by Steegy »

:lol:
I tried SDB = null; a thousand times, without luck (if only it was that easy ;)). Maybe by using Late Binding, we can get rid of the warning. The Early Binding uses RCW (Runtime Callable Wrapper) and GC (Carbage Collection) and stuff like that, so it's very very difficult (or impossible) to control things yourself.
.NET makes a lot of things easy, except if really need to use COM, Shell, Kernel, Plugins, ... (the not-so-GUI stuff)
Last edited by Steegy on Thu Jun 21, 2007 12:13 pm, edited 1 time in total.
Extensions: ExternalTools, ExtractFields, SongPreviewer, LinkedTracks, CleanImport, and some other scripts (Need Help with Addons > List of All Scripts).
Abel
Posts: 38
Joined: Mon Dec 19, 2005 6:11 pm
Location: NYC

Post by Abel »

I don't know about the VB scripts, but in C++ if I have a .NET reference that I explicitly want to clean up I can do an explicit delete, even though it's a managed pointer.

I seem to remember that the explicit NOTHING assignment was the alternative solution for VBA in Excel, so you may indeed want to try that.

Abel
Abel
Posts: 38
Joined: Mon Dec 19, 2005 6:11 pm
Location: NYC

Post by Abel »

Steegy wrote::lol:
I tried SDB = null; a thousand times, without luck (if only it was that easy ;)).
Have you tried SDB = nothing; instead?

Abel
Peke
Posts: 17457
Joined: Tue Jun 10, 2003 7:21 pm
Location: Earth
Contact:

Post by Peke »

Is there Any way to free (iDispatch) in .NET. I seriously doubt that .NET missed something like that.

One small Q? Is there way to Kill var in .net and as soon as You kill it MM closes? (Just trying to figure this out, was reading .NET Interoperability: COM Interop and you all made me interested in this)
Best regards,
Peke
MediaMonkey Team lead QA/Tech Support guru
Admin of Free MediaMonkey addon Site HappyMonkeying
Image
Image
Image
How to attach PICTURE/SCREENSHOTS to forum posts
Steegy
Posts: 3452
Joined: Sat Nov 05, 2005 7:17 pm

Post by Steegy »

Just a desperate try:

Code: Select all

private void ScreenSaverForm_FormClosed(object sender, FormClosedEventArgs e)
{
    try
    {
        Marshal.FinalReleaseComObject(SDB);  // Don't (shouldn't be necessary)
        SDB = null;

        GC.Collect();  // Also not recommended
        GC.WaitForPendingFinalizers();  // Yeah, same as before.

        Process.GetCurrentProcess().Kill();   // Don't do this!!!
    }
    catch { }
}
Remark about not doing an own process kill: Why not? It's the easiest way to quickly get rid of the program and free all memory (at least, as long as you don't use not-GC-able objects). I do it a lot with MediaMonkey and Maxthon2 too.
Extensions: ExternalTools, ExtractFields, SongPreviewer, LinkedTracks, CleanImport, and some other scripts (Need Help with Addons > List of All Scripts).
darchangel
Posts: 26
Joined: Wed Nov 30, 2005 11:23 pm

Post by darchangel »

The longer I try to make sense of it the less sense it makes.

If I create a new app, create a reference to MM and set the reference to null when I shutdown, I get this COM warning. If I add a button to the form, the COM warning goes away. If I reference any embedded resource, I get the COM warning. I've also found another dozen idiosyncrasies that make no sense. I've invested a lot of time into making this because when I began I thought MM was good for development. Now I'm ready to give up on it altogether. The experience has been entirely infuriating.

I hope this at least works for all the VBScript-ers out there because it is a nightmare in .NET
Post Reply