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

Implement IDisposable in IImageProcessor<TPixel> instances. #990

Merged
merged 3 commits into from
Aug 26, 2019

Conversation

JimBobSquarePants
Copy link
Member

Prerequisites

  • I have written a descriptive pull-request title
  • I have verified that there are no overlapping pull-requests open
  • I have verified that I am following matches the existing coding patterns and practice as demonstrated in the repository. These follow strict Stylecop rules 👮.
  • I have provided test coverage for my change (where applicable)

Description

Touches #967. Makes IImageProcessor<TPixel> inherit IDIsposable and ensures all implementations are correctly disposed.

Also ensures any overriding methods are calling their base implementation.

@codecov
Copy link

codecov bot commented Aug 26, 2019

Codecov Report

Merging #990 into master will decrease coverage by 0.11%.
The diff coverage is 90.9%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #990      +/-   ##
=========================================
- Coverage   89.72%   89.6%   -0.12%     
=========================================
  Files        1097    1097              
  Lines       48573   48621      +48     
  Branches     3421    3425       +4     
=========================================
- Hits        43581   43569      -12     
- Misses       4289    4297       +8     
- Partials      703     755      +52
Impacted Files Coverage Δ
...ng/Processors/Filters/PolaroidProcessor{TPixel}.cs 100% <100%> (ø) ⬆️
...Processing/Processors/Convolution/BokehBlurTest.cs 95.12% <100%> (ø) ⬆️
.../Processing/Processors/ImageProcessorExtensions.cs 100% <100%> (ø) ⬆️
...ors/Convolution/EdgeDetector2DProcessor{TPixel}.cs 100% <100%> (ø) ⬆️
...ocessors/Transforms/AutoOrientProcessor{TPixel}.cs 82.35% <100%> (+0.53%) ⬆️
...onvolution/EdgeDetectorCompassProcessor{TPixel}.cs 90% <100%> (+0.76%) ⬆️
...Processors/Convolution/BoxBlurProcessor{TPixel}.cs 100% <100%> (ø) ⬆️
...g/Processors/Filters/LomographProcessor{TPixel}.cs 100% <100%> (ø) ⬆️
...essing/Processors/Transforms/TransformProcessor.cs 100% <100%> (ø) ⬆️
...ssors/Convolution/GaussianBlurProcessor{TPixel}.cs 100% <100%> (ø) ⬆️
... and 36 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 13989ac...cda2586. Read the comment docs.

@codecov
Copy link

codecov bot commented Aug 26, 2019

Codecov Report

Merging #990 into master will increase coverage by 0.02%.
The diff coverage is 95.27%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #990      +/-   ##
==========================================
+ Coverage   89.72%   89.74%   +0.02%     
==========================================
  Files        1097     1098       +1     
  Lines       48573    48690     +117     
  Branches     3421     3433      +12     
==========================================
+ Hits        43581    43698     +117     
+ Misses       4289     4288       -1     
- Partials      703      704       +1
Impacted Files Coverage Δ
...ts/ImageSharp.Tests/Drawing/Paths/FillRectangle.cs 100% <ø> (ø) ⬆️
...ageSharp.Tests/Drawing/Paths/DrawPathCollection.cs 100% <ø> (ø) ⬆️
tests/ImageSharp.Tests/Drawing/Paths/FillPath.cs 100% <ø> (ø) ⬆️
tests/ImageSharp.Tests/Drawing/Text/DrawText.cs 100% <ø> (ø) ⬆️
...ImageSharp.Tests/Processing/ImageOperationTests.cs 97.5% <ø> (ø)
...ageSharp.Tests/Drawing/Paths/FillPathCollection.cs 100% <ø> (ø) ⬆️
...ageSharp.Tests/Processing/Filters/LomographTest.cs 100% <ø> (ø) ⬆️
...ests/ImageSharp.Tests/Drawing/Paths/FillPolygon.cs 100% <ø> (ø) ⬆️
...sts/Processing/BaseImageOperationsExtensionTest.cs 78.94% <ø> (ø)
...Processing/Processors/Convolution/BokehBlurTest.cs 95.12% <100%> (ø) ⬆️
... and 23 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 13989ac...d587c41. Read the comment docs.

Copy link
Member

@antonfirsov antonfirsov left a comment

Choose a reason for hiding this comment

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

I have pushed some tests revealing an issue in the implementation 😄

{
this.destination = cloningImageProcessor.CloneAndApply();
return this;
}
Copy link
Member

@antonfirsov antonfirsov Aug 26, 2019

Choose a reason for hiding this comment

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

If the processor is not a ICloningImageProcessor<TPixel> we are disposing and re-creating it unnecessarily.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch, will fix. 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe I'm just too tired but I cannot see a workaround here. The processors are created from different images.

Copy link
Member

Choose a reason for hiding this comment

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

Indeed, haven't noticed that!
Makes it harder, I will also keep thinking tomorrow.

/// Disposes the object and frees resources for the Garbage Collector.
/// </summary>
/// <param name="disposing">Whether to dispose managed and unmanaged objects.</param>
protected virtual void Dispose(bool disposing)
Copy link
Member

Choose a reason for hiding this comment

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

If we expect unmanaged objects (at least in theory) we should consider adding a finalizer.

In Image, I have distinnguished the dispose implementation by naming our method DisposeImpl. Still wondering if it's a good approach or we should rather Dispose(bool disposing), even if the bool parameter is dummy.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'd say stick with convention and use Dispose(bool disposing)

Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't use a finalizer since I didn't want to use (or condone) unmanaged object use.

this.MutateApply(useBounds);
}

this.cloningProcessorImpl.Verify(p => p.CloneAndApply(), Times.Once());
Copy link
Member

Choose a reason for hiding this comment

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

@JimBobSquarePants oops. We should expect this.cloningProcessorImpl.Verify(p => p.Apply(), Times.Once()); here instead. To avoid conflicts, I'll leave it to you.

@antonfirsov
Copy link
Member

We can skip the failing test and merge this as is for now. I may have an idea for unifying the regular and the cloning processor logic, and I can add it in a follow up PR.

Copy link
Member

@tocsoft tocsoft left a comment

Choose a reason for hiding this comment

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

👍 looking good

@antonfirsov antonfirsov merged commit 02d1f1b into master Aug 26, 2019
@antonfirsov antonfirsov deleted the js/idisposable-processors-967 branch August 26, 2019 23:58
antonfirsov pushed a commit to antonfirsov/ImageSharp that referenced this pull request Nov 11, 2019
…s#990)

* Implement IDisposable and ensure inheritance calls base

* add ImageProcessingContextTests and move some other test classes

* loosen up tests and leave TODO notes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants