ntwain
ntwain copied to clipboard
[Question] About the problem of increasing memory since the scan
Hello!
I'm trying to scan using 'Sample.Winform' inside the ntwain program source.
The function is working normally, and I am monitoring this program as a task manager.
However, after proceeding with the scan, I checked that the memory of the application continues to increase.
After scanning a large amount of paper documents, there is a risk of memory leak later.
Is there a way to manage memory properly?
Please give me some advice on this.
Thank you.
I had a similar issue. Every time I initiated a scan the memory usage would just continue to grow and no amount of disposes and forced garbage collection would help. The solution I ended up with was fairly simple. When calling the e.GetNativeImageStream be sure to make sure it is in a using clause like this if (e.NativeData != IntPtr.Zero) { using (Stream stream = e.GetNativeImageStream()) { if (stream != null) { img = Image.FromStream(stream); } } } It seems when the stream is put into a variable the system will not garbage collect even after flushing, closing, and disposing of the stream.