The DatImagenativexferWindowsTwainDsm() method in the TWAIN class makes a call to WindowsTwaindsmDsmEntryImagenativexfer that make the amount of ram to increase a lot. I scan in duplex mode (about 30 to 50 sheets/papers) and I always run out of memory.
Additional Details:
The method WindowsTwaindsmDsmEntryImagenativexfer is an external method located in "twaindsm.dll" so I don't know how to proceed and fix it.
After intensive research, I found the solution so you can scan without getting memory overflow or OutOfMemoryException. Basically we need to dispose (Bitmap) and free resources (IntPtr). Basically the fixes should be done in two methods of the TWAIN class. Last advise is: Do not store each retrieved bitmap in a list in memory because it also takes a lot of memory
Class: TWAIN
Method: NativeToBitmap(Platform a_platform, IntPtr a:intptrNative)
Solution: Add these sentences after Bitmap bitmap = new Bitmap(bitmapStream);;
Class: TWAIN
Method:STS DatImagenativexfer(DG a_dg, MSG a_msg, ref Bitmap a_bitmap)
Solution: The if (sts == STS.XFERDONE) block should look like this:
I'll write a more detailed and explained article on this, however not sure when but I will.
Thanks.
Diego Torres