0

I encounter with memory leak problem when I use Leptonica(class of lept4j library). When I call LeptUtils.convertImageToPix(fi) function in a for-loop, it goes to OutOfMemoryError: Java heap space exception.

for (BufferedImage fi : images) {
    Pix pix = LeptUtils.convertImageToPix(fi); // Memory leak is here
    TessAPI1.TessBaseAPISetImage2(api, pix);
    String line = TessAPI1.TessBaseAPIGetUTF8Text(api).getString(TessAPI1.TRUE);
    pdfContent.add(line);
}

I checked another parts of my code and only when it passes through convertImageToPix(...) method, PC's using memory increases.

Below I was trying to use dispose method of LeptUtils. It didn't help.

LeptUtils.disposePix(pix)

Do I possible clean memory to avoid this problem? if yes, how can I do it?

Ruslan Poltaev
  • 91
  • 1
  • 1
  • 5
  • Getting an `OutOfMemoryError` does not indicate that you have leak, only that you are using a comparatively large amount of memory. You can increase the amount of heap available via command-line options such as `-Xmx`. In as much as you appear to be generating *and retaining* an unknown number of potentially large objects, that may be exactly what you need to do. – John Bollinger Mar 23 '17 at 15:58
  • @JohnBollinger, I set this value to `-Xmx6096m`. Besides I used bigger value, but an application just was frozen. – Ruslan Poltaev Mar 23 '17 at 17:01
  • If you are trying to use more memory than the VM can acommodate, and there's no way to make it accommodate more, then your only alternative is to use less. I haven't enough information to suggest details. – John Bollinger Mar 23 '17 at 17:18

0 Answers0