Hi, I create a task using xTaskCreat(); Is it on my responsibility to free all memory usage before delete the task (using vTaskDelete()) or it is done automatically by freeRTOS kernel ? Is it on my responsibility to free all task stack and task TCB before delete the task (using vTaskDelete()) or it is done automatically by freeRTOS kernel ?
vTaskDelete will delete the task stack and TCB (either immediately if deleting another task, or deferred to the I(dle task if a task is deleting itself), assuming the task was created with dynamic memory (for a statically created task, vTaskDelete() will have FreeRTOS stop using that space, so it is now available to use to create another static task), All other resorces that the task has allocated need to be handled by your program, as FreeRTOS doesn’t know if they are still needed.
I’m using NewLib instead of FreeRTOS heap.c for dynamic memory allocation algorithm. NewLib dynamic memory allocation algorithm is different than FreeRTOS dynamic memory algorithm (heap.c). Are the thinkgs above about the vTaskDelete() operations are the same if I use NewLib ?
I recommend stepping through the very simple vTaskDelete() function in the debugger, or simply just looking at the short piece of source code that implements it, so you can see that Richard Damon’s clear answer is correct and holds in all cases – you will be able to see see exactly what the function does and does not do. FreeRTOS has no idea about any memory you allocated from Newlib.
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.