Skip to content

Commit

Permalink
Safely disposing GIF-related memory resources
Browse files Browse the repository at this point in the history
  • Loading branch information
emako committed Dec 20, 2024
1 parent 5220b0b commit df00f41
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using QuickLook.Common.Helpers;
using QuickLook.Common.Plugin;
using System;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
Expand All @@ -43,9 +44,9 @@ internal class GifProvider : AnimationProvider
private NativeProvider _nativeProvider;

private int[] _frameDelays; // in millisecond
private int _frameCount = 0;
private readonly int _frameCount = 0;
private int _frameIndex = 0;
private int _maxLoopCount = 0; // 0 - infinite loop
private readonly int _maxLoopCount = 0; // 0 - infinite loop
private int _loopIndex = 0;

private TimeSpan _minTickTimeInMillisecond = TimeSpan.FromMilliseconds(20);
Expand Down Expand Up @@ -95,20 +96,18 @@ public override void Dispose()

try
{
if (_bitmap != null)
lock (_bitmap ?? new object()) // Lock to prevent null reference exception
{
lock (_bitmap)
{
_stream?.Dispose();
_bitmap?.Dispose();
_bitmap?.Dispose();
_bitmap = null;

_bitmap = null;
_stream = null;
}
_stream?.Dispose();
_stream = null;
}
}
catch
catch (Exception e)
{
Debug.WriteLine(e);
}

_frame = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ namespace QuickLook.Plugin.ImageViewer;

public class MetaProvider
{
private readonly SortedDictionary<string, (string, string)> _cache =
new SortedDictionary<string, (string, string)>(); // [key, [label, value]]
private readonly SortedDictionary<string, (string, string)> _cache = []; // [key, [label, value]]

private readonly string _path;

Expand Down

0 comments on commit df00f41

Please sign in to comment.