Memory Leaks consuming Web services
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.
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 javax.xml.ws.Service 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 com.sun.org.apache.xml.internal.resolver.CatalogEntry 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? ...?