1

I'm analysing part of a Java 8 application using Java Mission Control. I'm using Java Mission Control 6.0.0 (the version that comes with Java 9 and 10). In the Memory view, under Java Application I see the following:

Java Mission Control Memory View Screenshot

87M seems like a lot of memory for lambdas, especially when seen in the context of the memory being used elsewhere. How should I interpret and perhaps optimise this memory use for the lambdas?

Adam
  • 682
  • 1
  • 6
  • 27

1 Answers1

1

You may want to take that number with a grain of salt, Flight Recorder samples memory allocations. I think it is misleading to show a total in bytes, since that kind of accuracy doesn't exist. A percentage that shows the "allocation pressure" would be better.

You can use the table to get a rough idea of where most of the allocation occurs, at least if you have a few hundred samples. This is similar to Hot Methods table that shows which Java code the JVM executes the most, but not the number of milleseconds methods have been executing.

If you want to remove unnecessary allocations, I would look at the stack trace and see if you could do something there.

Kire Haglin
  • 6,569
  • 22
  • 27
  • Thanks Kire. That's interesting. Do you think the reference to a lambda is likely to be a red herring then and in fact some other class is being instantiated here? – Adam Jul 30 '18 at 12:17
  • 1
    If you have a large number of samples, it's probably a real issue. It could be that you reference a field in you lambda, which you shouldn't really do if you use the stream API. If there is outside state, the JIT may not be able to remove the allocation. – Kire Haglin Jul 30 '18 at 13:06
  • 1
    OK. It sounds like it's well worth investigating then. Thanks for your help. – Adam Jul 30 '18 at 14:34