From 019a40791eb6ee5ed1487b3b5bc80884fcb86164 Mon Sep 17 00:00:00 2001 From: Mikey Sklar Date: Fri, 16 Oct 2026 18:56:21 -0700 Subject: [PATCH] Give Adafruit_GFX a virtual destructor except on AVR Deleting a canvas or display through an Adafruit_GFX pointer called only the base destructor, so the canvas buffer leaked (#369). AVR is left out because a virtual destructor links malloc and free into display sketches that never use the heap (+602 bytes on an Uno). Co-Authored-By: Claude Opus 5.5 (1M context) --- Adafruit_GFX.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Adafruit_GFX.h b/Adafruit_GFX.h index 7806f01..a75e5fb 100644 --- a/Adafruit_GFX.h +++ b/Adafruit_GFX.h @@ -19,6 +19,11 @@ class Adafruit_GFX : public Print { public: Adafruit_GFX(int16_t w, int16_t h); // Constructor +#if !defined(__AVR__) + // Virtual so deleting a canvas or display through an Adafruit_GFX pointer + // frees it. Skipped on AVR, where it links malloc/free into every sketch. + virtual ~Adafruit_GFX() {} +#endif /**********************************************************************/ /*!