I am using EE4 and every time I call _deviceSource.PreviewWindow = new PreviewWindow(new HandleRef(picBox, picBox.Handle));
the memory use increases by around 60 MB. The problem is that when I close the form and dispose all the resources on _job
and _devicesource
the system does not release the memory...even if I call CG.collect();
the system still uses those 60MB doing something. The problem is even worse if I try to call the form several times. At some point I get the Out of memory error because the memory utilization increases continuously.
Any suggestion? I check on the SDK samples and in all cases the problem persist. So my question is: is this a bug?
Asked
Active
Viewed 222 times
0
-
The leak is likely to be taking place with native domain (unmanaged) resources, especially video related, and possibly with third party libraries involved. It's hard to give advice without specific information, but you should perhaps `1` check what non-MS DLLs are loaded `2` does the problem take place in clean Windows – Roman R. Jul 01 '13 at 20:45
-
Thank you @Roman R. I will check for any non-Microsoft codec on the computer, but I have tried on different computers with the same result. Every time I execute the PreviewWindow property I can see an amount of memory that is not release even after the form is completed Disposed and the garbage collector is called. If I keep the parent form alive, every time I call the child form where the video is loaded the memory utilization increases. I tested some other examples that use Encoder 4 with the same result. – Timbolo Jul 02 '13 at 04:06
2 Answers
0
My mistake...! I was not Disposing correctly all the resources:
_deviceSource.PreviewWindow = null;
_job.RemoveDeviceSource(_deviceSource);
_deviceSource.Dispose();
releases all the memory resources used on the video.

Timbolo
- 1
- 1
0
I ran into the same issue today. I found that specifically you have to call source.PreviewWindow.Dispose()
before calling job.RemoveDeviceSource(source)
:
// The order in which we remove, dispose, and set null is very important.
// Anything less creates a huge memory leak.
// 1st Stop Encoding
job.StopEncoding();
// 2nd, Must Dispose the Preview Window
// Before Calling Job.RemoveDeviceSource << Absolutely
source.PreviewWindow.Dispose();
source.PreviewWindow = null;
// 3rd, Remove the Source
job.RemoveDeviceSource(source);
// 4th, Dispose the Source
source.Dispose();
source = null;
// 5th, Dispose the Job
job.Dispose();
job = null;

Jakob Möllås
- 4,239
- 3
- 33
- 61