Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


Memory Leak ?!

Posted by diodedan on August 1, 2009
Hi all,

I am using an Atmel atmega 128 running at 16 MHz. The settings are as follows:

#define configUSE_PREEMPTION1
#define configUSE_IDLE_HOOK0
#define configUSE_TICK_HOOK0
#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_FACILITY0
#define configUSE_16_BIT_TICKS1
#define configIDLE_SHOULD_YIELD1
#define configQUEUE_REGISTRY_SIZE0

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,

RE: Memory Leak ?!

Posted by diodedan on August 1, 2009
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?

RE: Memory Leak ?!

Posted by MEdwards on August 1, 2009
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

RE: Memory Leak ?!

Posted by SPaik on August 3, 2009
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.

[ Back to the top ]    [ About FreeRTOS ]    [ Privacy ]    [ Sitemap ]    [ ]

Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

FreeRTOS v10.2.1 is available for immediate download. MIT licensed, includes 64-bit RISC-V, NXP Cortex-M33 demo, Nuvoton Cortex-M23 demo & STM32H745 dual core (AMP) demo.

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


FreeRTOS and other embedded software careers at AWS.

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Cadence Tensilica Cortes

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers





STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner