After playing a playlist for about two days the memory increases from a about 100 megabytes to a few gigabytes. The thread count remains the same about 20 threads. I'm disposing of media (when changin to new media) from mediaplayer element like so:
if(web.MediaPlayer.Media != null) {
web.MediaPlayer.Media.Dispose();
}
web.MediaPlayer.Media = media;
and when creatinga new media player:
if(web.MediaPlayer != null) {
if(web.MediaPlayer.Media != null) {
web.MediaPlayer.Media.Dispose();
}
web.MediaPlayer.Dispose();
}
web.MediaPlayer = new MediaPlayer(media) { EnableHardwareDecoding = true };
Is this enough to dispose of the media like this?
And when reaching end i play next media like this, calling init video calls the first piece of code. Switching the media in the media player.
web.MediaPlayer.EndReached += (s, e) => ThreadPool.QueueUserWorkItem(_ => {
if(this.tab_objects.ContainsKey(tab_index)) {
tab tab_object = this.tab_objects[tab_index];
string next_media = tab_object.get_next_media();
....some other code....
if(next_media != null) {
this.init_video(next_media, tab_index, true);
} else {
}
}
});
Any help is appreciated.
I've altered the code to this with no results:
using(Media media = new Media(this.lib_vlc, uri)) {
using(MediaPlayer p = web.MediaPlayer) {
if(p != null) {
/*using(Media last_media = p.Media) {
if(last_media != null) {
last_media.Dispose();
}
}*/
}
web.MediaPlayer = null;
if(p != null) {
p.Dispose();
}
web.MediaPlayer = new MediaPlayer(media) { EnableHardwareDecoding = true };
media.Dispose();
}
}
I've commented out the "last_media" part because it has no effect. I set the web.MediaPlayer as null because it causes a crash when i dispose of the MediaPlayer object before setting it to something else.
I would wrapping the media in "using" and explicitly disposing of it would be enough. But the memory usage still climbs. What is the correct way of disposing of the last played media object?