If I execute the code below, an OutOfMemoryException occurs either in the line
using (Bitmap bitmap1 = new Bitmap(FrameToFilePath(interval.Start - 1)))
or string
using (Bitmap bitmap2 = new Bitmap(FrameToFilePath(interval.End + 1)))
when the inner statement to execute is executed approximately 1000 times.
However, I do not know why an OutOfMemoryException occurs. I seem to have written enough using to host Bitmap objects. Where is a memory leak?
class Program { static void Main(string[] args) {
EDIT : OK. Maybe because Parallel.ForEach starts tasks before other tasks finish, so more and more tasks start, but Bitmap were not GCed, because the tasks were not completed. Well, if so, how can I fix this to avoid an OutofMemoryException? I'm not sure if that is the case though ...
source share