Canon DR-C125 Not enough memory. (-4500) after ~30 pages

Issue #22 closed
Mike Lipin created an issue

I've got Canon DR-C125 and Win 8.1. When I put lots of paper there and set 300dpi + colorful mode it shows a window saying "Not enough memory. (-4500)" and stops working (no events raised) after ~30 pages.

This happens whatever ICapXferMech I set and whatever way I save the data when OnDataTransferred fires. The device supports File (bmp), Memory and Native. All three produces the issue but Native and bitmap saving take a bit longer to fail.

It doesn't happen if i choose settings producing smaller images.

I would say it's the scanner issue if the canon tool (DR-C125 CaptureOnTouch) act the same way. But it doesn't. I tried the same settings and scanned as many pages as i wanted. Unfortunately i didn't manage to find any meaningful information about the error. But i can say that it's not about my machine memory for sure.

I used your tests as examples so my code is pretty much the same and doesn't contain anything tricky. I even tried to set Native transfer then create a bitmap and do not save it and everything worked. As soon as I started saving the bitmaps (with or without disposing :)) it failed after ~30 pages.

I would really appreciate if you could identify and resolve the issue or show me a way to avoid the error.

Let me know if you need a test application or whatever would help to find a solution.

Thank you for the brilliant library. Your work is great!

Comments (7)

  1. Eugene Wang repo owner

    It may help to know

    1. how you're converting the data to an image (is it a dotnet's built-in image type?) since it may leak even when you have disposed the image (see SomeMethod method below), or
    2. what you're doing before disposing the image (other actions below). Maybe you're trying to display each image in the UI and a copy of the image could be made under the hood, or
    3. if not then is it a dotnet Save method? (vs using a third party lib save method).
    session.DataTransferred += (s,e) => {
      using(var img = SomeMethod(e)){
          // do nothing is okay
    
          // other actions?
    
          // save will cause memory error??
          // img.Save(...);
      }
    };
    
  2. Mike Lipin reporter

    Here you go Test project zip It's a winform project which reproduces my issue.

    I'm trying to scan pages and show images it as soon as it's ready. I scan to files and then use PictureBoxes to display the images from there. If i don't show boxes then everything works and I can scan any amount of images. If I show received images then i get Scanner error modal and scanner stops after 17 pages.

    I tried two different approaches to show images a) using Progress and b) using filewatcher both lead to the same result. I'm wondering how this code can affect scanner and make it throw the error. At the moment I don't know how I can show images as soon as it's scanned and not to get the error.

    Thanks!

  3. Eugene Wang repo owner

    If this is representative enough for your production code and not just for the sake of reproducing, then the problem is you're displaying & thus keeping every large 300dpi color image in the picturebox (or some similar thing) without reduction.

    In the case of a picture box, you want to generate a thumbnail for display purposes with small size (no bigger than what you want to display) like below. There are all kinds of thumbnail routines on internet so you'll want to find one that works for you.

    PictureBox pictureBox = new PictureBox()
    {
        Image = GenerateThumbnail(...);
    };
    
  4. Mike Lipin reporter

    It is kind of a customer wish to see lots of huge images. I understand that it's not a good way to go. I don't understand why the app consumes some "scanner" memory which ends instead of my machine memory. When I see the message I still have a lot of free memory space.

  5. Eugene Wang repo owner

    Depends on how large is acceptable. I doubt a full 300dpi image is really what they're looking for. Resize it down to around ~1000 pixel bounds will usually be reasonable enough.

    Don't know about using scanner memory. You should still see your app in task manager eating up memory as well no matter how much free memory you have available. If you're running as a 32bit process then things will start behaving badly when more than 1 GB is used by your app.

  6. Log in to comment