I realized that the destructors of the objects that I create locally within a task are not called when the task is eliminated.
I think this happens because the function of the task does not exit properly from its scope, and therefore the destructors of local objects are not called.
How can I solve this problem?
main.cpp
class MyClass
{
public:
MyClass()
{
buffer = (char*)malloc(5);
}
char* buffer;
//It is never called
~MyClass()
{
delete buffer;
}
};
static void MyTask(void *pvParameters)
{
MyClass my_class = MyClass();
//Delete this task
vTaskDelete(NULL);
}
You need to make all the resources be cleaned up before you call the vTaskDelete function. My wrapper functions that HS2 pointed to will (if vTaskDelete is enabled) delete the task when then task function returns. An alternative is to change you code to be like: