Stack after vTaskDelete

barbart1 wrote on Friday, June 18, 2010:

Hi,

I have a task that is called out by an ISR, when i press a button. This task creates another task. When i press the second button, ISR calls a third task that uses vTaskDelete to delete the second task.

Now before I create the second task, im checking available stack size by calling xPortGetFreeHeapSize(). I’m calling it again just after vTaskDelete deletes the second task. And the numbers don’t match. Why is that? I thought all the memory should be freed after calling vTaskDelete. After few ISR’s I’m getting a stack overflow. I’m using heap_2.c

davedoors wrote on Friday, June 18, 2010:

I have a task that is called out by an ISR,

Do you mean unblocked by an ISR? I don’t know what called out means.

ISR calls a third task that uses vTaskDelete to delete the second task.

Again I don’t really understand what you mean in this sentence. Tasks should not be called by an ISR so I suspect I just don’t understand your terminology.

Now before I create the second task, im checking available stack size by calling xPortGetFreeHeapSize().

xPortGetFreeHeapSize() tells you the heap size, not the stack size.

I’m calling it again just after vTaskDelete deletes the second task. And the numbers don’t match. Why is that? I thought all the memory should be freed after calling vTaskDelete. After few ISR’s I’m getting a stack overflow. I’m using heap_2.c

When a task is deleted the heap memory that was allocated to the task is freed from inside the idle task (by default anyway). Therefore you would not expect the numbers to match until the idle task had executed at least one cycle.

barbart1 wrote on Monday, June 21, 2010:

Sorry, I meant ‘unblocked by ISR’. The problem was the Idle Task - it was starved out of processing time. Everything works fine now, thanks.