I know that in Arduino you can't use delete
. So when does the destructor defined in C++ classes gets called?
Similarly, if I want to create a pointer to array, I would have to use malloc
and free
?
I know that in Arduino you can't use delete
. So when does the destructor defined in C++ classes gets called?
Similarly, if I want to create a pointer to array, I would have to use malloc
and free
?
The destructor is called when the object is destroyed. For automatic (on stack) variables, it's called after leaving its scope (
{}
). Read more about automatic variables.The destructor gets called when the variable goes out of scope or
delete
'd. This means, if you have nodelete
you can only create non-POD structures in automatic memory.You cannot use
malloc
andfree
, because constructors and destructors will not be called.But, you can try create your own
new
anddelete
like this: