tillrohrmann commented on a change in pull request #15162:
URL: https://github.com/apache/flink/pull/15162#discussion_r593082990



##########
File path: 
flink-core/src/main/java/org/apache/flink/core/memory/HybridMemorySegment.java
##########
@@ -132,10 +132,14 @@
     @Override
     public void free() {
         super.free();
+        runCleanerAtMostOnce();
+        offHeapBuffer = null; // to enable GC of unsafe memory
+    }
+
+    private synchronized void runCleanerAtMostOnce() {
         if (cleaner != null) {
             cleaner.run();
         }
-        offHeapBuffer = null; // to enable GC of unsafe memory
         cleaner = null;
     }

Review comment:
       I understand the fix. But aren't we solving the problem at the wrong 
place? As far as I understand the `HybridMemorySegment` is not thread safe and 
should only be used by a single thread because otherwise we end up with 
corrupted data. Given this, why do we allow concurrent/multiple freeing 
operations to happen in the first place?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to