I can not overcome, not even overcome, and catch when the 2nd call of the object's finalizer occurs. All 3 objects must be destroyed in a certain order, if this happens in an arbitrary order, then either memory leaks or destruction of a static unmanaged object that is responsible for the performance of 3 presented objects
Creating objects:
- VlcInstance
- VlcMediaPlayer / VlcMedia
- VlcMedia / VlcMediaPlayer
Destruction:
- VlcMedia
- VlcMediaPlayer
- VlcInstance
In case of removal of the function of object finalizers, and using exclusively destructor, all classes work exactly as needed.
If possible, tell me where in this code finalizers are called, except for exiting from Main
The c # code that controls objects:
using System; namespace libvlc.net.test.csharp { class Program { static VlcInstance vlcInstance; static VlcMediaPlayer vlcPlayer; static VlcMedia vlcMedia; static void Main(string[] args) { string path = System.IO.Path.Combine("..\\..\\libvlc-data\\2.2.6\\bin\\", IntPtr.Size == 4 ? "x86\\" : "x64"); vlcInstance = new VlcInstance(path, "-I", "logger,none", "-vv", "--no-plugins-cache", "--ignore-config"); vlcPlayer = new VlcMediaPlayer(vlcInstance); ConsoleKeyInfo cki; while(((cki = Console.ReadKey(true)).Key != ConsoleKey.Escape)) { switch (cki.Key) { case ConsoleKey.Spacebar: vlcPlayer.TooglePause(); break; case ConsoleKey.RightArrow: vlcPlayer.Stop(); if (!(vlcMedia is null)) { vlcMedia.MediaEvent -= VlcMedia_MediaEvent; vlcMedia.Dispose(); } vlcMedia = new VlcMedia(vlcInstance, new Uri(System.IO.Path.Combine("https://raw.githubusercontent.com/isyami/libvlc.net/master/", "test2"))); vlcMedia.MediaEvent += VlcMedia_MediaEvent; vlcPlayer.Open(vlcMedia); break; case ConsoleKey.LeftArrow: vlcPlayer.Stop(); if (!(vlcMedia is null)) { vlcMedia.MediaEvent -= VlcMedia_MediaEvent; vlcMedia.Dispose(); } vlcMedia = new VlcMedia(vlcInstance, new Uri(System.IO.Path.Combine("https://raw.githubusercontent.com/isyami/libvlc.net/master/", "test"))); vlcMedia.MediaEvent += VlcMedia_MediaEvent; vlcPlayer.Open(vlcMedia); break; } } vlcMedia = null; vlcPlayer = null; vlcInstance = null; GC.WaitForPendingFinalizers(); GC.Collect(); } private static void VlcMedia_MediaEvent(object s, VlcMediaEventArgs a) { switch (a.EventType) { case VlcMediaEvent.MetaChanged: Console.WriteLine($"{a.EventType}: \t\t{a.EventData.NewMeta}"); break; case VlcMediaEvent.SubItemAdded: Console.WriteLine($"{a.EventType}: NewSubItem"); break; case VlcMediaEvent.DurationChanged: Console.WriteLine($"{a.EventType}: \t{a.EventData.NewDuration}"); break; case VlcMediaEvent.ParsedChanged: Console.WriteLine($"{a.EventType}: \t\t{a.EventData.NewParsed}"); break; case VlcMediaEvent.Freed: Console.WriteLine($"{a.EventType}: \t\tMediaFreed"); break; case VlcMediaEvent.StateChanged: Console.WriteLine($"{a.EventType}: \t\t{a.EventData.NewState}"); break; default: break; } } } }