0

my java application works ~1 day, (I use different libs for processing photo like ffmpeg, javacv, javacpp) and then I see that my app use 9,5Gb RAM.

system monitoring tools

I don't understand why my app use so a lot of memory.

I set -Xmx6G

In VisualVM I see that heap space size 188M

heap space in visualVM

Meta Space use 141M

metaspace in visualVM

May be this helps

allocated bytes in visualVM

I read articles that Java use more RAM than heap space because there are JIT, Heap space, meta space, code, ant etc. But 9.5Gb is a lot of on my mind

Edited:

  • Yes my app some times have exceptions java.lang.OutOfMemoryError: Java heap space
Dinexpod
  • 41
  • 5

1 Answers1

2

I partly solve this problem, partly thanks Samuel Audet comment. (But whatever heap spase use stable 125M, metaspace 100M but java process use 1,4Gb )

So problem was in code where I get frames from video.

My old code:

FFmpegFrameGrabber g = new FFmpegFrameGrabber(file);
Java2DFrameConverter bimConverter = new Java2DFrameConverter();

g.start();

Frame grab = g.grab();
BufferedImage imageFrame = bimConverter.convert(grab);

g.stop();

And I couldn't even think until I checked all potentially classes that FFmpegFrameGrabber, Java2DFrameConverter, Frame is Autoclosable and we need for each call close() when instance.

And in some part of code not close InputStream

Good code:

FFmpegFrameGrabber g = new FFmpegFrameGrabber(file);
Java2DFrameConverter bimConverter = new Java2DFrameConverter();

g.start();

Frame grab = g.grab();
BufferedImage imageFrame = bimConverter.convert(grab);

g.stop();

g.close();
bimConverter.close();
grab.close();
Dinexpod
  • 41
  • 5