-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Class does not have a virtual destructor #369
Comments
A class automatically has a GFX objects are rarely deleted at all. Usually they just sit at the top of a sketch as globals. So users don't typically run into this base pointer deletion problem. No libraries delete GFX pointers. They actually can't because it's an abstract base class. So any GFX user who wants a polymorphic delete will be doing it in application code. So they can make a class derived from some GFX class, give it a virtual destructor, and they'd use that in their delete statements? |
The And in ESPEasy I do allow for these classes to be constructed and destructed in runtime as it is used in a plugin which can be enabled or disabled. |
There is a number of libraries inheriting from the class in this library.
For example:
Which by itself is also inherited by other libraries, like this one:
Neither
Adafruit_SPITFT
, norAdafruit_GFX
have virtual destructors.Thus you cannot safely call
delete
on a base pointer to an instance of such class as it will cause a memory leak.See also: StackOverflow - When to use virtual destructors?
I would really like these to have a virtual destructor.
But I can imagine it may add a slight overhead in some situations, which may be an issue on some micro controller use cases.
Would it be an idea to allow for some generic solution, to be used in all Adafruit libraries, to have this virtual destructor optional at compile time?
For example something like this:
This should then be done in the header files of all library classes which will be inherited from.
Thus in this example at least in
Adafruit_SPITFT
andAdafruit_GFX
The text was updated successfully, but these errors were encountered: