Skip to main content

Memory Leaks consuming Web services

Please note these forums are being decommissioned and use the new and improved forums at
6 replies [Last post]
Joined: 2010-12-02


I have a problem with memory leaks (or perhaps more likely erroneous usage by me) when using JAX-WS for consuming web services. I seem to have the same problem using either JAX-WS 2.2 as included in Netbeans or with the latest 2.2.1 version.

Short background:
I am responsible for a monitor application. This monitor shows the status for a number of server applications located on different servers. Every few minutes the monitor application connects to the servers through a number of web services and fetches status information.

Right or wrong, every time the monitor application fetches the server status I create a new and a Port from the service. After a few hours of doing this the memory in my application runs out. Using profiling tools I can see that I have a lot of objects which doesnt seem to get garbage collected as I would have thought. The payload in these objects seem to be the URL to a XML file on a server (parts of the wsdl I think). I can see no close (or similar) method on either the service or port object so I just let those objects fall out of scope to be garbage collected, which alas doesnt seem to happen.

The reason for creating a new service/port every time is that the server can be down or unreachable. It seemed simpler to always create new service/ports as the status-fetching is neither time-critical nor frequent. The user can also "on-demand" enter a IP number and get the status for any application on that server which also influenced the implementation in the direction of creating new service/ports as they are used.

So, what am I doing wrong? Have I missed a close method on the service or port? Should I reuse the service object for different servers? ...?


Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2007-05-14

We're facing exactly the same issue.
It seems that CatalogManager holds a CatalogEntry[] with all ever created CatalogEntry.
That's why they are not garbage collected.
All this ends in OOME, that's a shame.
As Jesper stated, shall we reuse service/ports objects ?
Are they thread-safe ?
What if the endpoint address can change in time ?

EDIT: Using JAX-WS 2.1.4 here

Joined: 2007-05-14

Ok, it seems we have to reuse the Service but we can getFooPort() and configure it at each call.
Service seems to be thread safe and is the one that is expensive to instanciate and that register CatalogEntry instances to CatalogManager.
This way, no more OOME.

Joined: 2013-10-07

Is this a known bug? Using service as static fixes the issue but why is it not being garbage collected in the first places.

Joined: 2010-10-19


Same problem here, same solution. eskatos is right. I've also tested it and it works. I statically initialize the web service object. Then, when every I previously create the service I simply only get the port using the service.getXYPort(). This also works when the web service is temporarily not available. That means, that the service object is more or less a container for the URL. That actual connection is made by sending a request using the port object. If the web service is unavailable, this method throws an exception, something like this: HTTP transport error: Connection refused

Then, if the web service has been recovered, you can call getXYPort() again using the same service instance. So no need to create a new service instance when handling an exception.

I still don't know, why this isn't mentioned in the API documentation...

Joined: 2005-11-08

Has anyone tried -Dxml.catalog.staticCatalog=false. This resolves the memory leak for my application, but, introduces an issue where my app times out when trying to get a web service endpoint. I found that property when reading about the CatalogManager class.
Regarding reusing the service; I'd prefer to close after each use and then get a fresh service for the next use to ensure a fresh connection.
Any thoughts?

Joined: 2011-01-04

Thank you (exact same issue here)