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

Sebastian Violet commented on CXF-8946:
---------------------------------------

I even tried to use a new RetryTemplate per call, but the leak is still there:
{code}
diff --git a/src/main/java/com/memoryleak/demo/jaxrs/StatusClientImpl.java 
b/src/main/java/com/memoryleak/demo/jaxrs/StatusClientImpl.java
index 2d2f04f..ea968e6 100644
--- a/src/main/java/com/memoryleak/demo/jaxrs/StatusClientImpl.java
+++ b/src/main/java/com/memoryleak/demo/jaxrs/StatusClientImpl.java
@@ -27,13 +27,17 @@ public class StatusClientImpl implements StatusClient {
 
   @Builder.Default
   @NonNull
-  private RetryTemplate retryTemplate = RetryTemplate.builder()
-      .maxAttempts(1)
-      .noBackoff()
-      .build(); //No retries
+  private RetryTemplate retryTemplate = getRetryTemplate(); //No retries
+
+  private static RetryTemplate getRetryTemplate() {
+    return RetryTemplate.builder()
+        .maxAttempts(1)
+        .noBackoff()
+        .build();
+  }
 
   private <T> T doWithRetry(Function<StatusClient, T> functionToRetry) {
-    return this.doWithRetry(functionToRetry, this.retryTemplate);
+    return this.doWithRetry(functionToRetry, this.getRetryTemplate());
   }
 
   private <T> T doWithRetry(Function<StatusClient, T> functionToRetry, 
RetryTemplate templateToUse) {
 {code}

> HttpClient in CXF causing memory leak
> -------------------------------------
>
>                 Key: CXF-8946
>                 URL: https://issues.apache.org/jira/browse/CXF-8946
>             Project: CXF
>          Issue Type: Bug
>          Components: JAX-RS
>    Affects Versions: 4.0.3
>            Reporter: Sebastian Violet
>            Priority: Major
>         Attachments: CXF-HTTPClient-MemoryLeak.zip, Screenshot 2023-10-19 at 
> 2.29.56 PM.png, java_pid17394.hprof.zip, java_pid17394_Leak_Suspects.zip, 
> java_pid91652.0001.hprof.zip, java_pid91652.0001_Leak_Suspects.zip, 
> memory-leak-demo.zip
>
>
> When processing requests using the JAX RS client which used the new 
> HttpClient, there is a memory leak.
> We found this when running it in spring boot using
> {code:java}
> @Async{code}
>  
> I have tried to reproduce it using the attached code, and it seems to work 
> with a low heap size.
>  
> You can execute the code like so:
> {code:java}
> mvn compile exec:exec{code}



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

Reply via email to