Page 1 of 1

Memory usage of xTaskCreate() within a task

Posted: Mon Nov 25, 2019 4:09 am
by zliudr
If I allocated x amount of stack for task 1, then task 1 calls xTaskCreate() to create task 2, giving it y amount of stack, then would the y amount come out of the x amount or not? My hope is not. When a task ends, the memory is released, correct? Thanks.

Re: Memory usage of xTaskCreate() within a task

Posted: Mon Nov 25, 2019 9:35 am
by ESP_Sprite
No. Task memory is allocated using malloc() (well, technically it's a version of malloc that only allocates from internal memory) and freed using free() when vTaskDelete() is called and the idle task gets the chance to clean up the task. In other words: The stack of the calling task is unaffected, and the memory will be returned to the heap after a task is cleaned up.

Re: Memory usage of xTaskCreate() within a task

Posted: Mon Nov 25, 2019 1:21 pm
by zliudr
Thanks. Should the task call vTaskDelete itself before returning?
Regarding internal memory, is wrover psram considered internal? What memory is not internal?

Re: Memory usage of xTaskCreate() within a task

Posted: Mon Nov 25, 2019 3:07 pm
by ESP_Dazz
  • vTaskDelete() itself does not return the memory when deleting a current running task. The memory is instead free in the IDLE task.
  • SPI RAM is not internal

Re: Memory usage of xTaskCreate() within a task

Posted: Tue Nov 26, 2019 4:45 am
by zliudr
Thanks for clarifying. Then what does the psram do in wrover modules? Hash space other than task stacks, like allocating large memory blocks? Could you point me to some documentation on different ESP32 memories and psram?

Re: Memory usage of xTaskCreate() within a task

Posted: Wed Nov 27, 2019 7:48 am
by ESP_Sprite
Yes, exactly. You retrieve blocks of memory using malloc() and friends, so it gets used anywhere where large blocks of memory are allocated this way.

Re: Memory usage of xTaskCreate() within a task

Posted: Sun Dec 01, 2019 2:20 am
by zliudr
So If I enable psram in menuconfig and compile my code, then psram gets automatically used whenever malloc() runs? Thanks.