0

I have a JAX-RS webservice served using Tomcat 6. I'm using Guice to inject my resources and to create the Servlet.

I've definitely got a memory leak and I assume this is because I'm not handling either the end of the request or the shutdown of the App.

If I continually refresh requests against the service I can see that the memory use of Tomcat climbs and doesn't reduce until I recycle Tomcat.

I've attempted to RTFM but I'm not grokking the lifecycle.

I create the Servlet using

public class RadWebServiceServletConfig extends GuiceServletContextListener {
   @Override
   protected Injector getInjector() {
      return Guice.createInjector(new JerseyServletModule() {
         @Override
         protected void configureServlets() {
            // Must configure at least one JAX-RS resource or the 
            // server will fail to start.
            bind(Crags.class);
            bind(IDataFacade.class).to(DataFacade.class);
            bind(IRepository.class).to(Repository.class);
             //filter all requests to log
            filter("/*").through(LoggingFilter.class);

            // Route all requests through GuiceContainer
            Map<String, String> params = new HashMap<String, String>();
            params.put("com.sun.jersey.spi.container.ContainerRequestFilters",
                        "com.sun.jersey.api.container.filter.GZIPContentEncodingFilter");
            params.put("com.sun.jersey.spi.container.ContainerResponseFilters",
                    "com.sun.jersey.api.container.filter.GZIPContentEncodingFilter");
            serve("/*").with(GuiceContainer.class, params);
         }
      });
   }
}

So am I being silly? Where do I catch the end of requests or the app context?

Paul D'Ambra
  • 7,629
  • 3
  • 51
  • 96

1 Answers1

0

I'd suggest switching to regular servlets and drop the guice-servlet extension, at least to find it if it's the cause.

The additional Guice libraries (e.g. guice-servlet, guice-persist) are rather buggy.

I'm not aware about any memory leaks per-se, but guice-servlet re-implements the whole Servlet infrastructure, see f.e. those bugs: http://code.google.com/p/google-guice/issues/list?q=RequestDispatcher

It's also using a ThreadLocal, when one mentions memory leaks those should be immediately suspect, see http://code.google.com/p/google-guice/source/browse/extensions/servlet/src/com/google/inject/servlet/GuiceFilter.java

Jakub Bochenski
  • 3,113
  • 4
  • 33
  • 61