diff --git a/lcl/imagelistcache.pas b/lcl/imagelistcache.pas index 6ca765dad2..d3199a16f5 100644 --- a/lcl/imagelistcache.pas +++ b/lcl/imagelistcache.pas @@ -181,7 +181,10 @@ begin FListeners.Remove(AListener); end; if FListeners.Count = 0 then + begin + FImageListCache := nil; Free; + end; end; procedure TImageListCache.RegisterBitmap(AListener: IImageCacheListener; ABitmap: TBitmap; ABitmapCount: Integer = 1); diff --git a/lcl/include/buttonglyph.inc b/lcl/include/buttonglyph.inc index 6f087a4445..9d66c548ed 100644 --- a/lcl/include/buttonglyph.inc +++ b/lcl/include/buttonglyph.inc @@ -31,7 +31,10 @@ end; destructor TButtonGlyph.Destroy; begin if FImagesCache <> nil then + begin FImagesCache.UnregisterListener(Self); + FImagesCache := nil; // cache can free on unregister + end; FOriginal.Free; FOriginal := nil; inherited Destroy; @@ -99,7 +102,10 @@ end; procedure TButtonGlyph.GlyphChanged(Sender: TObject); begin if FImagesCache <> nil then + begin FImagesCache.UnregisterListener(Self); + FImagesCache := nil; // cache can free on unregister + end; if (FOriginal.Width > 0) and (FOriginal.Height > 0) then begin