Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task Cleanup leaks 160B of Memory #522

Open
smallbraingames opened this issue Mar 14, 2025 · 1 comment
Open

Task Cleanup leaks 160B of Memory #522

smallbraingames opened this issue Mar 14, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@smallbraingames
Copy link
Contributor

Bug description

If a FreeRTOS task is created with ThreadSpawnConfig, it leaks 160 bytes in memory when cle

  • Would you like to work on a fix? [y/n]

To Reproduce

  1. Create any task with threadspawnconfig, then join and drop it
  2. Check the memory usage before and after
 loop {
        log::info!("\n");
        log::info!("============== BEFORE TEST TASK ===========");
        print_memory_info();
        let test_task = spawn("test\0", 1024 * 10, 1, Some(Core::Core0), move || {
            sleep(Duration::from_secs(3));
        });
        test_task.join().unwrap();
        log::info!("\n");
        log::info!("============== AFTER TEST TASK ===========");
        print_memory_info();
    }

and in print_memory_info,

 log::info!(
            " Free: {} bytes",
            heap_caps_get_free_size(MALLOC_CAP_INTERNAL)
        );

Expected behavior

It to clean up the task fully

Environment

  • esp-idf-svc 0.51
  • Target device (MCU): esp32s3
@smallbraingames smallbraingames added the bug Something isn't working label Mar 14, 2025
@ivmarkov
Copy link
Collaborator

Are you sure that you are observing a memory leak caused by spawning (std::thread::spawn) the new thread, and NOT observing the allocation of the thread-local memory for the ThreadSpawnConfig keys itself?

Two experiments you could do to confirm/deny:

  • Experiment 1: Do not call spawn but still call the ThreadSpawnConfig setup. If you still see a memory "leak", you are observing the ThreadSpawnConfig local storage allocation in heap, rather than anything else.
  • Experiment 2: Do what you do now, but offload the ThreadSpawnConfig as well the subsequent std::thread::spawn call in another, "outer" thread, which is also spawned with std::thread::spawn, but does not have a ThreadSpawnConfig setup. Once both threads are joined, you should not see a "memory leak" anymore, as the ThreadSpawnConfig local storage of the outer thread should die when this thread is joined.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Todo
Development

No branches or pull requests

2 participants