From d2f06d30ed7b154f3df0d25aa35e216d050d167c Mon Sep 17 00:00:00 2001 From: barelyprofessional <150058423+barelyprofessional@users.noreply.github.com> Date: Thu, 25 Dec 2025 20:42:17 -0600 Subject: [PATCH] With the power of Claude free, will this memory still leak? --- KfChatDotNetBot/Commands/Kasino/SlotsCommand.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/KfChatDotNetBot/Commands/Kasino/SlotsCommand.cs b/KfChatDotNetBot/Commands/Kasino/SlotsCommand.cs index 9ed8337..4996dc6 100644 --- a/KfChatDotNetBot/Commands/Kasino/SlotsCommand.cs +++ b/KfChatDotNetBot/Commands/Kasino/SlotsCommand.cs @@ -510,12 +510,12 @@ public class SlotsCommand : ICommand using var animated = new Image(500, 900); foreach (var rImg in frames) { - var bytes = new byte[rImg.Width * rImg.Height * 4]; - Marshal.Copy((IntPtr)rImg.Data, bytes, 0, bytes.Length); - using var frame = SixLabors.ImageSharp.Image.LoadPixelData(bytes, rImg.Width, rImg.Height); + // FIX: Use Span to wrap unmanaged memory directly - NO ALLOCATION! + var span = new Span(rImg.Data, rImg.Width * rImg.Height * 4); + // LoadPixelData can work with Span directly + using var frame = SixLabors.ImageSharp.Image.LoadPixelData(span, rImg.Width, rImg.Height); frame.Frames.RootFrame.Metadata.GetWebpMetadata().FrameDelay = 2; animated.Frames.AddFrame(frame.Frames.RootFrame); - // Note: frame is disposed automatically via 'using' } if (animated.Frames.Count > 1) animated.Frames.RemoveFrame(0);