The problem is this, there is a program, win form, a panel on it that shows video, video files are taken from the directory, read into an array and chase around, video display class (source is taken from msdn and slightly altered)

namespace MediaPlayer { class MediaPly { internal const int WS_CHILD = 0x40000000, WS_VISIBLE = 0x10000000, LBS_NOTIFY = 0x00000001, HOST_ID = 0x00000002, LISTBOX_ID = 0x00000001, WS_VSCROLL = 0x00200000, WS_BORDER = 0x00800000; private FilgraphManagerClass graphManager = new QuartzTypeLib.FilgraphManagerClass(); private IMediaControl mControl; private IMediaPosition mPosition; private IVideoWindow mWindow; public MediaPly() { } public bool LoadFile(string sfile, Panel parentHandler) { graphManager.RenderFile(sfile); mControl = graphManager; mPosition = graphManager; mWindow = graphManager; mWindow.Owner = parentHandler.Handle.ToInt32(); mWindow.WindowStyle = WS_CHILD; mWindow.SetWindowPosition(parentHandler.ClientRectangle.Left, parentHandler.ClientRectangle.Top, parentHandler.ClientRectangle.Width, parentHandler.ClientRectangle.Height); graphManager.Run(); return true; } public bool isStop() { if (graphManager.CurrentPosition == graphManager.Duration) { //graphManager.Stop(); //graphManager.CurrentPosition = 0; return true; } else return false; } public string nowSec() { return graphManager.CurrentPosition.ToString(); } public string allSec() { return graphManager.Duration.ToString(); } public void setCurPos (double pos) { graphManager.CurrentPosition = pos; } } } 

On the form:

 MediaPly _mp = null; public string filesPath = "video-files"; public string[] videofiles; public int countFiles = 0; public int playKey = 0; private void Form1_Load(object sender, EventArgs e) { this.Left = 0; this.Top = Screen.PrimaryScreen.Bounds.Height - this.Height; if (Directory.Exists(filesPath)) { videofiles = Directory.GetFiles(filesPath); countFiles = videofiles.Count(); if (File.Exists(videofiles[0])) { _mp = new MediaPly(); _mp.LoadFile(videofiles[0], this.panel1); timer1.Start(); //this.filePlay = fileName1; } } else { MessageBox.Show("directory " + filesPath + " no exists"); } } private void timer1_Tick(object sender, EventArgs e) { if (_mp.isStop()) { //_mp.setCurPos(0.01); playKey++; if (playKey + 1 > countFiles) playKey = 0; _mp = new MediaPly(); _mp.LoadFile(videofiles[playKey],this.panel1); } label1.Text = _mp.nowSec(); label2.Text = _mp.allSec(); label3.Text = videofiles[playKey] + " - " + playKey; } 

actually the problem is this, the files are spinning in a circle, everything is almost normal, but the process at the beginning of ~ 40mb in memory, I twist 3 mp4 files, shows about 2-3 laps of these files and the memory grows to 150-160 mb, and then reset back to 40 , but the problem is that when it is reset, 1 file does not show, i.e. there is a stop toli last frame of the previous file, toli first is new, as I understand it, when the memory reaches the limit, loads a new file and exceeds the space allocated for the process - the memory is reset along with the file that has just been downloaded and this file does not show .... seconds go that it is being played but the video is not there, after which the next files are played in a circle, and so again it loses several times, then the memory grows up and at that moment when it is reset - again it does not show one file ... in C # I’m noob, I don’t understand how is it working is melting, as the memory is reset, maybe there is an opportunity to somehow reset it after each playing file? or how else to solve this issue

  • so decided - private void timer1_Tick (object sender, EventArgs e) {if (_mp.isStop ()) {//_mp.setCurPos (0.01); playKey ++; if (playKey + 1> countFiles) playKey = 0; _mp = new MediaPly (); _mp.LoadFile (videofiles [playKey], this.panel1); GC.Collect (); } label1.Text = _mp.nowSec (); label2.Text = _mp.allSec (); label3.Text = videofiles [playKey] + "-" + playKey; } - levantez
  • tobish by adding GC.Collect (); after downloading the next file - levantez
  • That's right, do not care for the release of memory, let HZ cleans tons of generated garbage. This is how govnod is created. - nitrocaster
  • Well, tell me how to do otherwise? I could not find a method for a graph manager as a finalize () or something like that, only Stop () which doesn’t solve the problem at all - levantez