saraff-9EB1047A4BEB4cef8506B29BA325BD5A / Saraff.Twain.NET

Saraff.Twain.NET is the skillful scanning component which allows you to control work of flatbed scanner, web and digital camera and any other TWAIN device from .NET environment. You can use this library in your programs written in any programming languages compatible with .NET technology.
GNU General Public License v3.0
102 stars 35 forks source link

Possible memory leak #26

Closed bkraul closed 6 years ago

bkraul commented 6 years ago

When using Saraff.Twain component, during the AcquireCompleted event I am using:

var stream = new System.IO.MemoryStream();
mySaraffTwain.GetImage(i).Save(stream, ImageFormat.Tiff);

And then proceeding to save the stream to a file. I am disposing the stream after saving the file, but the memory used in the twain images does not seem to be disposed, the memory usage keeps climbing, and it is not disposed even after closing the form.

I have tried using the .Dispose() method of the component, to no avail. Is there something I need to do to cause memory used by the Twain component to be released?

saraff-9EB1047A4BEB4cef8506B29BA325BD5A commented 6 years ago

Hello, @bkraul You must self dispose all images that you receive using a GetImage method. As sample:

var _stream = new MemoryStream();
using(var _image = _twain.GetImage(i)) {
    _image.Save(stream, ImageFormat.Tiff);
}

Also, you can process a EndXfer event, as sample:

var _stream = new MemoryStream();
using(var _image = e.Image) {
    _image.Save(_stream, ImageFormat.Tiff);
}
bkraul commented 6 years ago

Thanks @saraff-9EB1047A4BEB4cef8506B29BA325BD5A. That seemed to alleviate the problem. I am marking this as resolved.