Deleting tasks
In some cases, it is advantageous to have a task run, and after it has accomplished everything needed, then remove it from the system. For example, in some systems with fairly involved startup routines, it might be advantageous to run some of the late initialization code inside a task. In this case, the initialization code would run, but there is no need for an infinite loop. If the task is kept around, it will still have its stack and Task Control Block (TCB) wasting FreeRTOS heap space. Deleting the task will free the task’s stack and TCB, making the RAM available for reuse. (In general, though, the critical initialization code should be run long before the scheduler starts.)
Many embedded programs will never delete tasks. There are many applications that do not require freeing up resources or dynamically allocating memory.
The task deletes itself
The simplest way to delete a task after it has finished doing useful work is to call vTaskDelete...