yshige / twaindotnet

Automatically exported from code.google.com/p/twaindotnet
0 stars 0 forks source link

Parameter is not valid. Freeing memory after scan #10

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.  Scan several (10+) pages with ADF and leave the test application open
2.  Scan several more pages (10+).  Program will throw an error trying to 
create the Bitmap in BitmapRender. Error is "parameter is not valid".

What is the expected output? What do you see instead?
It is expected that there would be a mechanism to free memory after a scan 
is complete.  Because the error only occurs on the 2nd scan, it is assumed 
that freeing the pointer allocated memory would prevent the crash.  
However, there is no proof to that assumption.  Even if freeing memory is 
not the cause of the error, it is necessary to free up memory to do 
extended scanning sessions without closing down the application.

What version of the product are you using? On what operating system?
Latest Version.  Vista x86

Please provide any additional information below.

Original issue reported on code.google.com by david.h...@medianotion.com on 19 Feb 2010 at 9:26

GoogleCodeExporter commented 9 years ago
I changed the BitmapRenderer.cs Dispose method to this:

        protected virtual void Dispose(bool disposing)
        {
            Kernel32Native.GlobalUnlock(_dibHandle);
            Kernel32Native.GlobalFree(_dibHandle);
        }

This freed the memory allocated for the image.  I write the image to disk 
rather than 
placing the image in a list.  this solved my problem.

Original comment by david.h...@medianotion.com on 20 Feb 2010 at 6:53

GoogleCodeExporter commented 9 years ago

Original comment by luke.qui...@gmail.com on 21 Feb 2010 at 11:04

GoogleCodeExporter commented 9 years ago
Hi David,

Could you please share your implementation?

Thanks

Original comment by baburaj....@gmail.com on 11 Mar 2010 at 12:26

GoogleCodeExporter commented 9 years ago
Honestly, I am no longer using TwainDotNet.  I needed some functionality it 
could not 
provide at this time.  Anyway, here is what I had before I stopped using it.  
See in 
DataSourceManager.FilterMessage where I write the image to file.  See in 
BitmapRenderer.Dispose where I free the memory after writing the file. HTH

Original comment by david.h...@medianotion.com on 11 Mar 2010 at 3:02

Attachments:

GoogleCodeExporter commented 9 years ago
Thanks David. That helped me.

Original comment by baburaj....@gmail.com on 15 Mar 2010 at 2:45

GoogleCodeExporter commented 9 years ago
I've an update. Seems like we need to reopen this defect. Though David's sample
helped me to get this working for around 6 scans (Duplex, 600dpi, B&W) without 
any
issue TwainDotNet crashes with OutOfMemoryException as I try with more pages. 
Memory
usage by the application as I could notice from Task manager is around 900MB. Is
there any better way to manage Memory?

Original comment by peri...@gmail.com on 17 Mar 2010 at 1:21

GoogleCodeExporter commented 9 years ago
Sorry I didn't realise that this issue didn't reopen. I think perhaps 
DataSourceManager 
would need to be changed to fire an event as each image came in instead of 
queuing them 
all up into a list.

Original comment by luke.qui...@gmail.com on 1 Apr 2010 at 12:19

GoogleCodeExporter commented 9 years ago
If anybody is still looking for a solution,  Instead of collecting the 
pointer "picturePointers.Add(hbitmap)" in DataSourceManager.TransferPictures, I 

invoked a thread that saves the image.  Without the thread, the scanner will be 
forced to wait while the image is being saved.  To keep track of the images, I 
created a List<filenames>.

Original comment by jeff.he...@gmail.com on 11 May 2010 at 11:48

GoogleCodeExporter commented 9 years ago
Hi Jeff,

I am interested in the solution that you have proposed as I am facing a similar 
issue. When I am using the app to scan more than 50-60 images using ADF the app 
crashes with OutOfMemoryException.

If you have tested your code and it works for such a scenario, Can you please 
share your updated code file(s) here?

If you have not tested your code for such a scenario, I will test it for even 
larger scans and post my findings here.

Original comment by tejesh.p...@gmail.com on 9 Sep 2010 at 6:53

GoogleCodeExporter commented 9 years ago
Hi Tejesh,
 Unfortunately I am unable to share my code with you.  I did test it with a high speed scanner (90DPI-180PPI) with over 250 sheets in duplex mode.   It worked as expected.

The fix was simple; pass the image pointer and the new file name into a thread 
that saves the image. After the scanning was complete, I waited for all the 
threads to complete.   

I wish I could be more specific but I have not seen that block of code since I 
wrote it.

-Jeff

Original comment by jeff.he...@gmail.com on 10 Sep 2010 at 1:33

GoogleCodeExporter commented 9 years ago
Hi all!
I recently except same problem, and i notice that memory used by Bitmap 
objects. 
Then i manually call Dispose on Bitmap in TransferImageEventArgs after save 
image to temp file.
It solve the problem, and program can scan any huge ammount of pages.
Good luck ;)

Original comment by zgg...@gmail.com on 17 Feb 2012 at 9:36

GoogleCodeExporter commented 9 years ago
Hello zgg,

Can you please tell me where you put that Dispose(). I've been having the same 
issue. Or can you please send me the file to my email?

Thanks,
-Hameed

Original comment by faif...@gmail.com on 24 Apr 2012 at 4:05