users@jersey.java.net

Re: [Jersey] memory leak with CDI ?

From: Moises Lejter <moilejter_at_gmail.com>
Date: Fri, 23 Jul 2010 22:59:13 -0500

To get the simple stuff out of the way - until a GC actually runs, you should see the amount of memory in use increase - your JAX-RS resources (explicitly, or in general by default) are created on each call, and only used for that one call. So you would expect memory use to increase, until GC cleans up.

You could annotate your resource to be a singleton, instead, to see if memory use remains stable ...

Moises

On Jul 23, 2010, at 10:45 PM, satish gopalakrishnan wrote:

> Hi,
> I am using glassfish v 3.01. I have the simplest of applications - a hello world resource and a helloService which is empty. When I access it repeatedly using just wget, after a while I see that the memory usage keeps increasing - basically a memory leak. Here is the code
>
>
> @Path("/hello")
> @RequestScoped
> public class HelloWorldResource {
>
> @Inject
> HelloService helloService;
> public String helloWorldTest(){
> helloService.toString();
> return "xyz"
> }
> }
>
> Am I doing something wrong here ? This is the simplest possible application with CDI and jersey - so somewhat surprised that this can have a memory leak. I tried @managedBean as well. Same result.
>
> My web.xml looks like this
>
> <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
> <init-param>
> <param-name>javax.ws.rs.Application</param-name>
> <param-value>mtest.HelloApplication</param-value>
> </init-param>
> </servlet>
>
>
> Any help / insights would be greatly appreciated
>
> thanks