1

Closed

Not all DLLs unloaded on Dispose

description

When
VlcContext.CloseAll();
is used then not all Handles are closed.

In LibVlcInteropsManager add Field
private string myLibVlcDllsDirectory;
In private void InitVlcLib(string libVlcDllsDirectory) add this.myLibVlcDllsDirectory = libVlcDllsDirectory;.
Example:
private void InitVlcLib(string libVlcDllsDirectory)
{ ...
if (!File.Exists(libVlcCoreFilePath))
    throw new FileNotFoundException("Libvlccore library not found in directory.");

this.myLibVlcDllsDirectory = libVlcDllsDirectory;

myLibVlcCoreDllHandle = Win32Interop.LoadLibrary(libVlcCoreFilePath);
...}
In public void Dispose() add following lines at the bottom of the method:
foreach (ProcessModule module in Process.GetCurrentProcess().Modules)
{
    if (!(module.FileName.StartsWith(this.myLibVlcDllsDirectory) && module.FileName.EndsWith("_plugin.dll")))
    {
        continue;
    }

    Win32Interop.FreeLibrary(module.BaseAddress);
}

foreach (ProcessModule module in Process.GetCurrentProcess().Modules)
{
    if (!module.FileName.StartsWith(this.myLibVlcDllsDirectory))
    {
        continue;
    }

    Win32Interop.FreeLibrary(module.BaseAddress);
}
Don't forget to add System.Diagnostics to usings.

EDIT:

I found another issue when using subs then some dlls are reference more than once so you need to change my above code in public void Dispose() from
foreach (ProcessModule module in Process.GetCurrentProcess().Modules)
{
    if (!(module.FileName.StartsWith(this.myLibVlcDllsDirectory) && module.FileName.EndsWith("_plugin.dll")))
    {
        continue;
    }

    Win32Interop.FreeLibrary(module.BaseAddress);
}
to
bool contains;
do
{
    foreach (ProcessModule module in Process.GetCurrentProcess().Modules)
    {
        if (
            !(module.FileName.StartsWith(this.myLibVlcDllsDirectory)
            && module.FileName.EndsWith("_plugin.dll")))
        {
            continue;
        }

        Win32Interop.FreeLibrary(module.BaseAddress);
    }

    contains = false;
    foreach (ProcessModule module in Process.GetCurrentProcess().Modules)
    {
        if (!module.FileName.StartsWith(this.myLibVlcDllsDirectory)
            || !module.FileName.EndsWith("_plugin.dll"))
        {
            continue;
        }

        contains = true;
        break;
    }
}
while (contains);

file attachments

Closed Apr 18 at 12:30 PM by ZeBobo5
Reclosed, modifications added.

Thanks for your feedback.

ZeBobo5

comments

gansquer wrote Jan 27 at 11:04 AM

Hi,

Thanks for this message but I have a problem on the Dispose() method.The code does not compile with this error : "The name 'Process' does not exist in the current context"

I've correctly add System.Diagnostics to using but it seems that it references the system.dll v4.0.30319 for Silverlight instead of the system.dll v2.0.50727 from the project "Vlc.DotNet.Core"

gregor4005 wrote Jan 27 at 12:37 PM

Interesting error... You are correct, the reference should be system.dll v2.0.50727I don't get that error because I am not developing Silverlight projects.Maybe it works when you place the using inside the namespace?

Anyway, I uploaded my compiled version of Vlc.DotNet.Core.Interops

ZeBobo5 wrote Apr 18 at 9:36 AM

** Closed by ZeBobo5 04/18/2014 1:36AM

gregor4005 wrote Apr 18 at 11:16 AM

I reopened this issue because i recently detected another issue regarding multiple references of the some dlls when using subtitles. I added the fix to the description.