Should `write` with an `END_TOKEN` call `finalize` on the stream to prevent memory leaks?
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 35/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- julia
- 领域
- performance
调研方向
从文档中的 TOKEN_END 示例以及 src/stream.jl 中约第 174–183 行的流生命周期代码开始。使用 Julia 代码片段重现泄漏,然后比较所提议的 finalize、finalizer 和 closed-mode 行为。Done 应保留底层缓冲区,同时及时释放转码流的资源。
由索引模型根据 Issue 内容生成。
描述
The desire here is to close the TranscodingStream without closing the underlying buffer. This is documented in https://juliaio.github.io/TranscodingStreams.jl/latest/examples/#Explicitly-finish-transcoding-by-writing-TOKEN_END-1 and says that you should write a TOKEN_END token to the stream. However, an issue with that is that it only flushes the stream but it doesn't finalize it which leads to memory leaks in code written like:
using CodecZlib
using TranscodingStreams
function leak()
buf = IOBuffer()
data = rand(10^6)
while true
zWriter = ZlibCompressorStream(buf)
write(zWriter, data)
write(zWriter, TranscodingStreams.TOKEN_END)
flush(zWriter)
end
end
leak()
which will indefinitely leak. Manually calling finalize on the zWriter fixes the issue but it is not clear from the documentation that this is required. There are a few possible solutions:
- Attach a finalizer to the stream that calls
finalize. This is not ideal because you want a more eager cleanup than whenever the GC gets to it. - Make writing a
TOKEN_ENDcallfinalizeon the stream. - Make writing a
TOKEN_ENDset the stream mode to:closedand thereby allowingcloseon the wrapper stream to not close the underlying wrapped stream : https://github.com/JuliaIO/TranscodingStreams.jl/blob/2fac97171c2ff7b6828f49e34c22eb929cb672a1/src/stream.jl#L174-L183
Alternatively, it is also possible that the code that shows the leak above is "faulty" but generally, normal Julia code shouldn't leak like this so at least a finalizer might be a good idea.
- 主要语言
- Julia
- 星标
- 90
- 派生
- 26
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
JuliaIO/TranscodingStreams.jl 的其他 Issue
-
Allow generic `DenseVector{UInt8}` as input/output可能已有人在做 @nhz2 于 460 天前认领。 未关闭
难度 3/5 1-2 天 新手友好度 45/100
JuliaIO/TranscodingStreams.jl#247 · 2 条评论 ·
-
难度 5/5 一周以上 新手友好度 30/100
JuliaIO/TranscodingStreams.jl#246 · 1 条评论 ·
-
Support libaec?未关闭
难度 3/5 1-2 天 新手友好度 25/100
JuliaIO/TranscodingStreams.jl#207 · 2 条评论 ·
-
API for Buffer未关闭
难度 5/5 一周以上 新手友好度 35/100
JuliaIO/TranscodingStreams.jl#202 · 2 条评论 · 1 个 reaction ·
-
难度 4/5 3-5 天 新手友好度 25/100
JuliaIO/TranscodingStreams.jl#188 ·
查看 JuliaIO/TranscodingStreams.jl 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 66/100
-
question
难度 2/5 1-3 小时 新手友好度 68/100
brown-ccv/Chamber.jl#272 ·
-
难度 2/5 1-3 小时 新手友好度 78/100
JuliaAstro/SolarPosition.jl#143 ·
-
distributions
难度 2/5 1-3 小时 新手友好度 72/100
JuliaBayes/Wren.jl#404 · 2 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
JuliaAI/MLJTransforms.jl#113 ·
维护者通常 1 天内回复