This may not be applicable anymore, but there was some version of the CLR that certainly had errors with LOH, where images are usually distributed. You can check this topic. The workaround was to manually check if there was enough consistent memory (to allocate external memory) before allocating, which is a little painful to do in C #. Just suppose you cannot do something wrong.
I also had problems using OpenCV / Emgu and using opencvsharp for some problems. This is a more direct shell in which you must be very careful in allocating memory. It has been a while, and I cannot remember the exaxt problem. This is due to memory allocation. It should also be fixed, I think.
The presence of both dependencies ends and does not help with clean code.
Otherwise, try using the using statement, which other answers offer. It calls .Dispose () automatically and immediately starts the GC. This way your memory does not fragment. You can also write ..
using(Image a, Image b, Image c, ...) {}
... while the object implements IDisposable
source share