You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cxf.apache.org by "Andriy Redko (Jira)" <ji...@apache.org> on 2023/03/14 00:25:00 UTC

[jira] [Comment Edited] (CXF-8827) Reusing of JAX-RS Client causes memory leak

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

Andriy Redko edited comment on CXF-8827 at 3/14/23 12:24 AM:
-------------------------------------------------------------

[~mormegil] it is true that the CXF JAX-RS client creates a client per target (basically per URL). The question is - why do you create so many targets? You could easily have a single WebTarget per base URL and vary the query / matrix / ... params and HTTP methods.


was (Author: reta):
[~mormegil] it is true that the CXF JAX-RS client creates a client per target (basically per URL). The question is - why do you create so many targets? You could easily have a single WebTarget per base URL and vary the path / query / matrix / ... params and HTTP methods.

> 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)