# Multiple xTaskCreate calls consume all memory

**URL:** <https://forums.freertos.org/t/multiple-xtaskcreate-calls-consume-all-memory/6037>\
**Category:** Kernel\
**Created:** [June 30, 2016, 1:05pm UTC](https://forums.freertos.org/t/multiple-xtaskcreate-calls-consume-all-memory/6037 "2016-06-30T13:05:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [June 30, 2016, 1:05pm UTC](https://forums.freertos.org/t/multiple-xtaskcreate-calls-consume-all-memory/6037/1 "2016-06-30T13:05:06Z")

</div>

**[hytromo](https://sourceforge.net/u/hytromo/)** wrote on [Thursday, June 30, 2016](https://sourceforge.net/p/freertos/discussion/382005/thread/e3fd47ac/#62d0):

Our processor runs a server in the background which listens for commands. We can command it to send a low value to a pin, wait a bit, and then reset the pin to the default high value.

Because of the running server, It is important that the above process is executed as a separate task.

As stated here [http://www.freertos.org/a00126.html](http://www.freertos.org/a00126.html), we create the task (via `xTaskCreate(mixer, "Mixer", UINT32_C(2048), NULL, UINT32_C(2), &mixerTask)`) which calls the following function:

```auto
void mixer(void * pvParameters) {
        (void) pvParameters;
        
        // set PIN LOW code here

        vTaskDelay(1000);

         // set PIN HIGH code here

       vTaskDelete(mixerTask); // delete the task itself (memory is scheduled for being freed)

}

```

The task runs each time our server receives a specific command, which is ~10-20 seconds.

Apart from the server, we have a timer (created via `vTimerCreate`) running every 600ms performing a simple task.

The problem is that we run out of memory after 3 calls to the `vTaskCreate` function. Searching the web reveals that the IDLE task is responsible for freeing the memory after the call to `vTimerDelete`.

Should we create this IDLE task ourselves or how else can we solve this problem?

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [June 30, 2016, 1:23pm UTC](https://forums.freertos.org/t/multiple-xtaskcreate-calls-consume-all-memory/6037/2 "2016-06-30T13:23:05Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Thursday, June 30, 2016](https://sourceforge.net/p/freertos/discussion/382005/thread/e3fd47ac/#62d0/aea4):

The idle task is created automatically - you do not need to create it  
yourself. However, if you are deleting tasks (or in FreeRTOS V9 just if  
a task deletes itself) you do need to ensure the idle task gets some  
processing time. The idle task runs at the idle priority (stating the  
obvious ;o) which is priority 0. If you have tasks above priority zero  
that never enter the Blocked state (don’t call vTaskDelay(),  
vTaskDelayUntil(), or otherwise enter the Blocked state to wait for a  
queue/semaphore/direct to task event) then the Idle task will never run

- and I suspect that is your problem.

As an aside, why do you create and delete a task each time anyway? When  
the command is given you can set the pin low and reset a software timer.  
Once the software timer expires its callback function can set the pin  
high again.
