[ 
https://issues.apache.org/jira/browse/CXF-8827?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17705361#comment-17705361
 ] 

Petr Kadlec commented on CXF-8827:
----------------------------------

[~reta] Oh, sure, that’s a possible workaround if you know you are using 
specifically CXF as the JAX-RS implementation (and you have some specific set 
of base URLs). However, if you code only against the JAX-RS specification 
(however naive that may be…), this is not really an option, I’d say. (In other 
words: That’s not how you would code it, meaning your generic code would work 
fine in other implementations but leak with CXF.)

> 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
>            Priority: Major
>
> 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