Memory Leak ?!

Hi all, I am using an Atmel atmega 128 running at 16 MHz. The settings are as follows: #define configUSE_PREEMPTION        1 #define configUSE_IDLE_HOOK            0 #define configUSE_TICK_HOOK            0 #define configCPU_CLOCK_HZ            ( ( unsigned portLONG ) 16000000 ) #define configTICK_RATE_HZ            ( ( portTickType ) 500 ) #define configMAX_PRIORITIES        ( ( unsigned portBASE_TYPE ) 3 ) #define configMINIMAL_STACK_SIZE    ( ( unsigned portSHORT ) 85 ) #define configTOTAL_HEAP_SIZE        ( (size_t ) ( 2000 ) )//Atmega 128 has 4kbyte of SRAM (about half now) #define configMAX_TASK_NAME_LEN        ( 8 ) #define configUSE_TRACE_FACILITY    0 #define configUSE_16_BIT_TICKS        1 #define configIDLE_SHOULD_YIELD        1 #define configQUEUE_REGISTRY_SIZE    0 I’ve been able to get three tasks to work. However, this crazy problem happens where after some time, two of the tasks fail, but the third task continues to operate. This problem seems indicative of a memory leak! My question becomes: how does one prevent this leak? I’ve been using static variables in my local functions. Also, the tasks call other functions. Could the stack overflow from this? Any hints/personal experiences? Thanks much, diodedan

Memory Leak ?!

I guess my major questions are: 1) How do "static" variables in local functions interact with FreeRTOS and its memory scheme? 2) Why do two tasks that normally work fine alone fail when  they are running together (and after some time, approx 6-10 mins) 3) How can I debug this?

Memory Leak ?!

What makes you think it is a memory leak? FreeRTOS only allocates memory when a task or queue is created, so a memory leak would seem doubtful. Are you tasks using dynamic memory allocation? If so then they may be leaking memory or suffering fragmentation issues. You can check for stack overflows http://www.freertos.org/Stacks-and-stack-overflow-checking.html and http://www.freertos.org/uxTaskGetStackHighWaterMark.html

Memory Leak ?!

Don’t forget that malloc() may not be thread safe.  If you are using your system’s malloc() inside of tasks, you might want to wrap it inside of something like a semaphore to protect it.