He-Pin opened a new issue, #3226:
URL: https://github.com/apache/pekko/issues/3226

   ### Motivation
   
   `ActorGraphInterpreter` 关闭后,`GraphInterpreterShell` 中闭包捕获的 `self`(ActorRef)和 
`interpreter` 引用未被置为 null。如果外部持有 materialized Source 的引用,可能导致已关闭的 shell 无法被 GC 
回收。
   
   ### 当前代码行为
   
   `ActorGraphInterpreter.scala` 中:
   
   ```scala
   // ActorGraphInterpreter.scala:572-585
   lazy val interpreter = new GraphInterpreter(...) {
     override def onAsyncInput(...): Unit = {
       self ! AsyncInput(...)  // 闭包捕获 self
     }
   }
   ```
   
   `postStop`(约 848-866 行)虽然清理了 `activeInterpreters` 集合,但 
`GraphInterpreterShell` 实例中的 `self`(ActorRef)和 `interpreter`(lazy 
val)引用仍然存在。如果用户代码保留了 materialized Source/Flow 的引用,shell 对象可能被间接持有。
   
   ### 预期行为
   
   `postStop` 应将 `interpreter` 和关键引用置为 null,断开与已关闭 actor 的引用链。
   
   ### 代码证据
   
   - 
`stream/src/main/scala/org/apache/pekko/stream/impl/fusing/ActorGraphInterpreter.scala:572-585`
 — shell 中闭包捕获 self
   - 
`stream/src/main/scala/org/apache/pekko/stream/impl/fusing/ActorGraphInterpreter.scala:848-866`
 — postStop 清理逻辑
   
   ### 复现方式
   
   创建大量短生命周期的流,保留 materialized 值的引用,用 heap dump 分析是否有已关闭的 shell 实例残留。
   
   ### 影响范围
   
   - 模块:`pekko-stream`
   - 影响频繁创建/销毁流的场景
   - 长期运行应用中的潜在内存泄漏


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

To unsubscribe, e-mail: [email protected]

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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to