diff --git a/src/ImageSharp/Image.cs b/src/ImageSharp/Image.cs
index fe72ec5c00..22b9ce8e5c 100644
--- a/src/ImageSharp/Image.cs
+++ b/src/ImageSharp/Image.cs
@@ -3,6 +3,7 @@
using System;
using System.IO;
+using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
using SixLabors.ImageSharp.Advanced;
@@ -149,9 +150,9 @@ namespace SixLabors.ImageSharp
protected void UpdateSize(Size size) => this.size = size;
///
- /// Internal routine for freeing managed resources called from
+ /// Disposes the object and frees resources for the Garbage Collector.
///
- /// /// Whether to dispose of managed objects.
+ /// Whether to dispose of managed and unmanaged objects.
protected abstract void Dispose(bool disposing);
///
@@ -161,7 +162,7 @@ namespace SixLabors.ImageSharp
{
if (this.isDisposed)
{
- ThrowHelper.ThrowObjectDisposedException(this.GetType());
+ ThrowObjectDisposedException(this.GetType());
}
}
@@ -182,6 +183,9 @@ namespace SixLabors.ImageSharp
/// The token to monitor for cancellation requests.
internal abstract Task AcceptAsync(IImageVisitorAsync visitor, CancellationToken cancellationToken);
+ [MethodImpl(InliningOptions.ColdPath)]
+ private static void ThrowObjectDisposedException(Type type) => throw new ObjectDisposedException(type.Name);
+
private class EncodeVisitor : IImageVisitor, IImageVisitorAsync
{
private readonly IImageEncoder encoder;
diff --git a/src/ImageSharp/ImageFrameCollection.cs b/src/ImageSharp/ImageFrameCollection.cs
index 8c8edcd7a5..07ba8c87f3 100644
--- a/src/ImageSharp/ImageFrameCollection.cs
+++ b/src/ImageSharp/ImageFrameCollection.cs
@@ -4,6 +4,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
+using System.Runtime.CompilerServices;
namespace SixLabors.ImageSharp
{
@@ -198,14 +199,14 @@ namespace SixLabors.ImageSharp
{
if (this.isDisposed)
{
- ThrowHelper.ThrowObjectDisposedException(this.GetType());
+ ThrowObjectDisposedException(this.GetType());
}
}
///
- /// Internal routine for freeing managed resources called from
+ /// Disposes the object and frees resources for the Garbage Collector.
///
- /// /// /// Whether to dispose of managed objects.
+ /// Whether to dispose of managed and unmanaged objects.
protected abstract void Dispose(bool disposing);
///
@@ -262,5 +263,8 @@ namespace SixLabors.ImageSharp
/// The background color.
/// The new frame.
protected abstract ImageFrame NonGenericCreateFrame(Color backgroundColor);
+
+ [MethodImpl(InliningOptions.ColdPath)]
+ private static void ThrowObjectDisposedException(Type type) => throw new ObjectDisposedException(type.Name);
}
}