11// Copyright (c) Six Labors and contributors.
22// Licensed under the Apache License, Version 2.0.
33
4+ using System ;
45using System . IO ;
56
67using SixLabors . ImageSharp . Advanced ;
@@ -80,21 +81,11 @@ internal Image(
8081 /// </summary>
8182 Configuration IConfigurable . Configuration => this . Configuration ;
8283
83- /// <summary>
84- /// Gets a value indicating whether the image instance is disposed.
85- /// </summary>
86- public bool IsDisposed { get ; private set ; }
87-
8884 /// <inheritdoc />
8985 public void Dispose ( )
9086 {
91- if ( this . IsDisposed )
92- {
93- return ;
94- }
95-
96- this . IsDisposed = true ;
97- this . DisposeImpl ( ) ;
87+ this . Dispose ( true ) ;
88+ GC . SuppressFinalize ( this ) ;
9889 }
9990
10091 /// <summary>
@@ -109,7 +100,7 @@ public void Save(Stream stream, IImageEncoder encoder)
109100 Guard . NotNull ( encoder , nameof ( encoder ) ) ;
110101 this . EnsureNotDisposed ( ) ;
111102
112- EncodeVisitor visitor = new EncodeVisitor ( encoder , stream ) ;
103+ var visitor = new EncodeVisitor ( encoder , stream ) ;
113104 this . AcceptVisitor ( visitor ) ;
114105 }
115106
@@ -144,9 +135,15 @@ public abstract Image<TPixel2> CloneAs<TPixel2>(Configuration configuration)
144135 protected void UpdateSize ( Size size ) => this . size = size ;
145136
146137 /// <summary>
147- /// Implements the Dispose logic.
138+ /// Disposes the object and frees resources for the Garbage Collector.
139+ /// </summary>
140+ /// <param name="disposing">Whether to dispose of managed and unmanaged objects.</param>
141+ protected abstract void Dispose ( bool disposing ) ;
142+
143+ /// <summary>
144+ /// Throws <see cref="ObjectDisposedException"/> if the image is disposed.
148145 /// </summary>
149- protected abstract void DisposeImpl ( ) ;
146+ internal abstract void EnsureNotDisposed ( ) ;
150147
151148 private class EncodeVisitor : IImageVisitor
152149 {
0 commit comments