Skip to content

Commit

Permalink
remove finalizer
Browse files Browse the repository at this point in the history
  • Loading branch information
nhz2 committed Dec 18, 2024
1 parent 87bfb21 commit 1b50b0b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 19 deletions.
11 changes: 1 addition & 10 deletions src/classic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ function ClassicPatch(patch_io::IO, new_size::Int64 = typemax(Int64))
diff = TranscodingStream(compressor(), IOBuffer())
data = TranscodingStream(compressor(), IOBuffer())
patch = ClassicPatch(patch_io, new_size, ctrl, diff, data)
finalizer(finalize_patch, patch)
return patch
end

Expand All @@ -36,17 +35,9 @@ function read_start(::Type{ClassicPatch}, patch_io::IO)
diff = TranscodingStream(decompressor(), diff_io)
data = TranscodingStream(decompressor(), data_io)
patch = ClassicPatch(patch_io, new_size, ctrl, diff, data)
finalizer(finalize_patch, patch)
return patch
end

function finalize_patch(patch::ClassicPatch)
for stream in (patch.ctrl, patch.diff, patch.data)
# must be called to avoid leaking memory
TranscodingStreams.changemode!(stream, :close)
end
end

function write_finish(patch::ClassicPatch)
for stream in (patch.ctrl, patch.diff, patch.data)
write(stream, TranscodingStreams.TOKEN_END)
Expand All @@ -61,7 +52,7 @@ function write_finish(patch::ClassicPatch)
write(patch.io, v)
end
flush(patch.io)
finalize(patch)
nothing
end

function encode_control(
Expand Down
10 changes: 1 addition & 9 deletions src/endsley.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ function write_start(
write_int(patch_io, new_size)
stream = TranscodingStream(compressor(), patch_io)
patch = EndsleyPatch(stream, new_size)
finalizer(finalize_patch, patch)
return patch
end

Expand All @@ -25,19 +24,12 @@ function read_start(::Type{EndsleyPatch}, patch_io::IO)
EndsleyPatch(TranscodingStream(decompressor(), patch_io), new_size)
end

function finalize_patch(patch::EndsleyPatch)
if patch.io isa TranscodingStream
# must be called to avoid leaking memory
TranscodingStreams.changemode!(patch.io, :close)
end
end

function write_finish(patch::EndsleyPatch)
if patch.io isa TranscodingStream
write(patch.io, TranscodingStreams.TOKEN_END)
end
flush(patch.io)
finalize(patch)
nothing
end

function encode_control(
Expand Down

0 comments on commit 1b50b0b

Please sign in to comment.