Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory Leak: BufferWriter Array Return Failure #76

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

DJGosnell
Copy link

Found a bug where the SequenceSegment<T>.Memory was being set to default prior to the RefCountedSegment.ReleaseImpl() method invocation. This has the effect of the implementation attempting to return default Memory<byte>.Empty array which is discarded by the pool. The GC obviously picks this up in the end, but it prevents the pool from reusing the memory.

The fix for this is changing the order of the setting of the memory to default and the ReleaseImpl invocation.

Added a test for this fix. I encountered one failure of BufferWriterTests.BufferWriterDoesNotLeak() but I could not reproduce the onetime failure. Unless I'm missing something, I don't see how this modification would cause the test failure.

@mgravell
Copy link
Owner

mgravell commented Jul 3, 2023

Interesting catch. Will read carefully asap

DJGosnell added a commit to DJGosnell/Pipelines.Sockets.Unofficial that referenced this pull request Jul 3, 2023
Added BufferWriter<T>.Deallocate to deallocate passed sequences.
Added test from PR mgravell#76.
Fixed MutexSlimTests due to the internal classes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants