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

Fix IDisposable usage #411

Merged
merged 2 commits into from
Aug 2, 2024
Merged

Conversation

Bykiev
Copy link
Contributor

@Bykiev Bykiev commented Aug 1, 2024

This PR fixes a memory leak in FontReader class with Woff2 fonts. Because of this FontReader class now implements IDisposable interface.
This PR also wraps disposable types with using statements to remove warnings.

This PR fixes a memory leak in FontReader with Woff2 fonts. Because of this FontReader class now implements IDisposable interface.
This PR also wraps disposable types with using statements to remove warnings.
Copy link

codecov bot commented Aug 1, 2024

Codecov Report

Attention: Patch coverage is 92.85714% with 1 line in your changes missing coverage. Please review.

Project coverage is 86%. Comparing base (baca1eb) to head (154432a).
Report is 1 commits behind head on main.

Files Patch % Lines
src/SixLabors.Fonts/StreamFontMetrics.cs 50% 1 Missing ⚠️
Additional details and impacted files
@@          Coverage Diff          @@
##            main    #411   +/-   ##
=====================================
  Coverage     86%     86%           
=====================================
  Files        238     238           
  Lines      15257   15263    +6     
  Branches    2108    2109    +1     
=====================================
+ Hits       13240   13247    +7     
+ Misses      1546    1545    -1     
  Partials     471     471           
Flag Coverage Δ
unittests 86% <92%> (+<1%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@JimBobSquarePants JimBobSquarePants left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for looking into this!

The changes look good just with some minor updates required. Looking at this PR reminds me I need to do a thorough style cleanup of the codebase!

@@ -26,7 +26,7 @@ public Buffer(int length)
this.buffer = ArrayPool<byte>.Shared.Rent(bufferSizeInBytes);
this.length = length;

ByteMemoryManager<T> manager = new(this.buffer);
using ByteMemoryManager<T> manager = new(this.buffer);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dispose() doesn't actually do anything for this type but given that is an implementation detail disposing is probably appropriate.

However, the manager should be held as a private field of the parent Buffer<T> and disposed at the end of the parent lifecycle.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, didn't get the idea about the purpose of private field. You can contribute to my repo if you wish.

src/SixLabors.Fonts/FontReader.cs Show resolved Hide resolved
src/SixLabors.Fonts/FontReader.cs Outdated Show resolved Hide resolved
src/SixLabors.Fonts/Tables/Cff/CffDataDicEntry.cs Outdated Show resolved Hide resolved
Copy link
Member

@JimBobSquarePants JimBobSquarePants left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many thanks for this!

@JimBobSquarePants JimBobSquarePants merged commit fec131d into SixLabors:main Aug 2, 2024
8 checks passed
@Bykiev
Copy link
Contributor Author

Bykiev commented Aug 2, 2024

Many thanks for this!

Thank you for your hard work! I'll continue with disposable in ImageSharp project, it seems to be more complicated...

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