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?