diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/SpectralConverter{TPixel}.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/SpectralConverter{TPixel}.cs index ae4a90337..ec1c057b2 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/SpectralConverter{TPixel}.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/SpectralConverter{TPixel}.cs @@ -13,15 +13,15 @@ using SixLabors.ImageSharp.PixelFormats; namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder { - internal abstract class SpectralConverter + internal abstract class SpectralConverter : IDisposable { public abstract void InjectFrameData(JpegFrame frame, IRawJpegData jpegData); public abstract void ConvertStride(); + + public abstract void Dispose(); } - // TODO: componentProcessors must be disposed!!! - // TODO: rgbaBuffer must be disposed!!! internal class SpectralConverter : SpectralConverter where TPixel : unmanaged, IPixel { @@ -129,5 +129,15 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder this.PixelRowCounter += this.PixelRowsPerStep; } + + public override void Dispose() + { + foreach (JpegComponentPostProcessor cpp in this.componentProcessors) + { + cpp.Dispose(); + } + + this.rgbaBuffer.Dispose(); + } } } diff --git a/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs b/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs index eb4ed5b95..30024af95 100644 --- a/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs +++ b/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs @@ -215,7 +215,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg public Image Decode(BufferedReadStream stream, CancellationToken cancellationToken) where TPixel : unmanaged, IPixel { - var spectralConverter = new SpectralConverter(this.Configuration, cancellationToken); + using var spectralConverter = new SpectralConverter(this.Configuration, cancellationToken); this.scanDecoder = new HuffmanScanDecoder(stream, spectralConverter, cancellationToken);