@@ -88,16 +88,16 @@ internal static Bitmap MenuBitmap(string key, Action<Graphics, int> draw)
8888
8989 /// <summary>Invalidate the cache (call after theme change).</summary>
9090 /// <remarks>
91- /// Icons are disposed immediately (form icons are reassigned right after).
92- /// Bitmap entries are NOT disposed here because ToolStripMenuItem.Image may
93- /// still reference them. The caller must reassign menu images; old bitmaps
94- /// become unreferenced and are collected by GC/finalizer.
91+ /// Both icons and bitmaps are disposed immediately to prevent GDI handle leaks.
92+ /// Callers must reassign any ToolStripMenuItem.Image references after this call.
9593 /// </remarks>
9694 internal static void InvalidateCache ( )
9795 {
9896 foreach ( var icon in _cache . Values )
9997 icon . Dispose ( ) ;
10098 _cache . Clear ( ) ;
99+ foreach ( var bmp in _bmpCache . Values )
100+ bmp . Dispose ( ) ;
101101 _bmpCache . Clear ( ) ;
102102 }
103103
@@ -561,7 +561,8 @@ private static void DrawExportIcon(Graphics g, int s)
561561 using var pen = new Pen ( Color . White , 2f ) { EndCap = System . Drawing . Drawing2D . LineCap . ArrowAnchor } ;
562562 int cx = s / 2 ;
563563 g . DrawLine ( pen , cx , s - 6 , cx , 5 ) ;
564- g . DrawLine ( new Pen ( Color . White , 1.5f ) , s / 4 , s - 5 , s - s / 4 , s - 5 ) ;
564+ using var baseLine = new Pen ( Color . White , 1.5f ) ;
565+ g . DrawLine ( baseLine , s / 4 , s - 5 , s - s / 4 , s - 5 ) ;
565566 }
566567
567568 // ── Menu bitmap accessors for new icons ─────────────────────────────
@@ -931,7 +932,8 @@ private static void DrawPreferencesIcon(Graphics g, int s)
931932 cy + ( int ) ( ( r + 2 ) * Math . Sin ( a2 ) )
932933 ) ;
933934 }
934- g . FillEllipse ( new SolidBrush ( AppTheme . Bg ) , cx - ir + 1 , cy - ir + 1 , ( ir - 1 ) * 2 , ( ir - 1 ) * 2 ) ;
935+ using var centerBrush = new SolidBrush ( AppTheme . Bg ) ;
936+ g . FillEllipse ( centerBrush , cx - ir + 1 , cy - ir + 1 , ( ir - 1 ) * 2 , ( ir - 1 ) * 2 ) ;
935937 }
936938
937939 /// <summary>Import icon: green downward arrow into a tray.</summary>
0 commit comments