xintongsong commented on a change in pull request #15273: URL: https://github.com/apache/flink/pull/15273#discussion_r600192987
########## File path: flink-core/src/main/java/org/apache/flink/core/memory/MemorySegment.java ########## @@ -217,10 +222,14 @@ public int size() { /** * Checks whether the memory segment was freed. * + * <p>This method internally involves cross-thread synchronization. Do not use for performance + * sensitive code paths. + * * @return <tt>true</tt>, if the memory segment has been freed, <tt>false</tt> otherwise. */ public boolean isFreed() { - return address > addressLimit; + // in performance sensitive cases, use 'address > addressLimit' instead + return isFreedAtomic.get(); Review comment: I think we have both made a point. 1. A memory segment should deal with multiple-frees, concurrency, leaks regardless of memory type. 2. The unsafe memory (de-)allocation should be self-contained, without relying on the correctness of memory segment and its usages. To be specific, the cleaner itself should make sure it is called exactly once. I'm leaning towards `1` for its broader coverage, and is neutral to `2`. I think `2` might not be necessary if `1` works properly, but it does not harm to have such an extra safe net given that as far as I can see the price is high. -- 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: us...@infra.apache.org