Dispose of a pictureBox image without losing the pictureBox
<p>I am writing a program that will play a slideshow (among other things). The slideshow is controlled by a backgroundWorker, and is set to a while(true) loop so it will constantly play images. My problem is I'm not sure how to dispose of the old images so they don't take up memory (after a while the program throws an "Out of memory exception). If I call horPicBox.Image.Dispose() then it won't let me use the pictureBox at all after that.</p>

<p>Is there a way to release the old image from memory?? If I look at the diagnostic tools in VS, the memory goes up each time the image changes ...
<a href="https://i.stack.imgur.com/Amls2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Amls2.png" alt="enter image description here"></a></p>

<p>Note: ImagePaths is a List of the filepaths for the slideshow images.</p>

<p>This is the code the backgroundWorker runs:</p>

<pre><code>private void PlayImages()
    {
        Random r = new Random();
        int index;
        Stopwatch watch = new Stopwatch();

        while (true)
        {
            index = r.Next(imagePaths.Count);
            horPicBox.Image = Image.FromFile(imagePaths[index]);

            watch.Start();

            while (watch.ElapsedMilliseconds &lt; 5000)
            {

            }

            watch.Stop();
            watch.Reset();

            //picWorker.ReportProgress(0);
        }
    }
</code></pre>

<p>I can report progressChanged to the UI thread, but I'm not sure what I need to do from the UI thread (if anything) to release the old Image(s). Thanks in advance!!</p>