Petr Kadlec created CXF-8827:
--------------------------------

             Summary: Reusing of JAX-RS Client causes memory leak
                 Key: CXF-8827
                 URL: https://issues.apache.org/jira/browse/CXF-8827
             Project: CXF
          Issue Type: Bug
          Components: JAX-RS
            Reporter: Petr Kadlec


The [JAX-RS Client 
Javadoc|https://docs.oracle.com/javaee/7/api/javax/ws/rs/client/Client.html] 
states:

{quote}Clients are heavy-weight objects that manage the client-side 
communication infrastructure. Initialization as well as disposal of a Client 
instance may be a rather expensive operation. It is therefore advised to 
construct only a small number of Client instances in the application. Client 
instances must be properly closed before being disposed to avoid leaking 
resources.{quote}

However, in CXF, this is impossible. On every call to {{target}}, 
{{ClientImpl}} creates a fresh {{WebTargetImpl}} which then (during 
{{request}}) creates a {{WebClient}} instance _and registers it within its 
parent_. This {{baseClients}} collection only grows as long as the shared 
{{Client}} instance exists and is closed and released only when {{close}} is 
called on it, so that sharing causes a memory leak which cannot be prevented in 
any way.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to