users@jersey.java.net

[Jersey] Potential memory leak in Jersey2

From: Rakesh Kumar <zeddicus536_at_gmail.com>
Date: Thu, 26 May 2016 08:42:05 -0400

Hi,
I had recently migrated my REST APIs from Jersey 1 to Jersey 2 (2.22.1 to
be exact). The application is running as a spring boot app. The application
receives a fairly large amount of traffic. I profiled the application using
JMC(Java Mission Control) and noticed large amount of memory consumed by
Annotations (getEntityAnnotations()). More details in the jms screenshot:

​From the screenshot you can see that 312 Annotation[] objects hold 1.55 GB
of memory (~5 MB per array). I had break point in the
getEntityAnnotations() method
and observed that the Annotation[] contains only 3 annotations (HTTP
Method, Path and Consumes). The Annotation objects have only a few fields.
I am not able to explain the reason for the large size of the fields.
Additionally the size is increasing over time. More details in debugger
screenshot:

​Has anyone encountered a similar issue?

Additionally from the jms screenshot we can observe that half of the memory
is from Arrays.copyOf. This is because the getEntityAnnotations() method in
the OutboundMessageContext class clones the entityAnnotations array. This
particular implementation has been added in jersey 2.5 as a part of the
ticket JERSEY-2072 <https://java.net/jira/browse/JERSEY-2072>.. Is there a
particular reason for this.

I am using Java 1.8.0_60 and spring boot 1.3.2.RELEASE. Please let me know
if you need any additional details about the application or the environment

Thanks

Kiran




1.JPG
(image/jpeg attachment: 1.JPG)

2.JPG
(image/jpeg attachment: 2.JPG)