# Got a memory problem while playing video with Emgu CV

**URL:** <https://forum.opencv.org/t/got-a-memory-problem-while-playing-video-with-emgu-cv/14247>\
**Category:** Uncategorized\
**Tags:** emgu\
**Created:** [August 14, 2023, 10:00am UTC](https://forum.opencv.org/t/got-a-memory-problem-while-playing-video-with-emgu-cv/14247 "2023-08-14T10:00:16Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Passionate\_Programme](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/passionate_programme/32/7855_2.png) [@Passionate\_Programme](https://forum.opencv.org/u/Passionate_Programme)\
**Post date:** [August 14, 2023, 10:00am UTC](https://forum.opencv.org/t/got-a-memory-problem-while-playing-video-with-emgu-cv/14247/1 "2023-08-14T10:00:16Z")

</div>

I have a picture box on a windows forms project. I use an OpenFileDialog class to let the user pick a video file and then I load the Video into an Emgu CV VideoCapture object. Immediately the method to play video gets called then the memory profiler under diagnostic tools skyrockets and then the program quits. I learnt that this is a memory usage issue and I may not be managing the Bitmaps in my program so well. I am reading frames from the video into a single Mat variable initialized in the class. Why is my method causing memory issues. Check out my code below

```auto
private void PlayVideo(){
  //mat has been instantiated at the class level
  using(mat){
    while(video.Grab()){
      if(video.Read(mat)){
         //convert mat to bitmap and display in picture box
          pictureBox1.Image = ToBitmap(mat);
         //delay for 33 seconds to create video impression to user
          Task.Delay(33);
        }
     }
  }

}

```

Help me get rid of this memory issue in my code.
