p-ranav / indicators

Activity Indicators for Modern C++

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Memoryleak on ProgressSpinner

drony opened this issue · comments

commented

D (03:00:03.997) HEAP: Iteration: 232000 (diff 304 bytes)
V (03:00:04.006) Spinner: Created: 1407943886
V (03:00:04.011) Spinner: Destroyed: 1407943886
D (03:00:04.016) HEAP: Iteration: 231700 (diff 300 bytes)
V (03:00:04.025) Spinner: Created: -1271674128
V (03:00:04.030) Spinner: Destroyed: -1271674128
D (03:00:04.035) HEAP: Iteration: 231396 (diff 304 bytes)
V (03:00:04.044) Spinner: Created: 72749701
V (03:00:04.049) Spinner: Destroyed: 72749701
D (03:00:04.053) HEAP: Iteration: 231096 (diff 300 bytes)
V (03:00:04.063) Spinner: Created: -1957109953
V (03:00:04.067) Spinner: Destroyed: -1957109953
D (03:00:04.073) HEAP: Iteration: 230792 (diff 304 bytes)
V (03:00:04.082) Spinner: Created: 569508829
V (03:00:04.086) Spinner: Destroyed: 569508829
D (03:00:04.091) HEAP: Iteration: 230492 (diff 300 bytes)

every instance 304 or 300 bytes leaked

Is this on an existing sample? Can you provide a sample I can use to reproduce this?

commented

I'm working on an embedded device (esp32 with esp-idf) and very limited memory(~200kb) on this device. but i give you snippet.

measureHeapMemory(); //implement own logic

 indicators::ProgressSpinner spinner{
    option::PostfixText{"Checking credentials"},
    option::ForegroundColor{Color::yellow},
    option::SpinnerStates{std::vector<std::string>{"⠈", "⠐", "⠠", "⢀", "⡀", "⠄", "⠂", "⠁"}},
    option::FontStyles{std::vector<FontStyle>{FontStyle::bold}}
  };
free(spinner);

measureHeapMemory();//implement own logic

I don't see any leaks reported by valgrind on the progress_spinner sample on x86.

Can you share your menuconfig? (just the relevant bits - how much heap memory is available etc.) I have an ESP32 on my desk right now :) I'll test soon and see what's happening.

Additionally, on ESP32, are you using std::thread or FreeRTOS tasks? (Is the spinner running on such a task. If so, what is the task stack size?)

commented

I'm sorry look like my mistake:(

here is the correction

`

void FreeHeap(const char *msg)
{
static int last = -1;

int heap = heap_caps_get_free_size(MALLOC_CAP_DEFAULT);

if (last != -1)
{
	ESP_LOGI( "HEAP", "%s: %d (diff %d bytes)", msg, heap, last - heap);
}
else
{
	ESP_LOGI("HEAP", "%s: %d", msg, heap);
}
last = heap;

}

extern "C" void app_main(void)
{
using namespace indicators;

printf("Hello world!\n");

FreeHeap("Before");

for (size_t i = 0; i < 10; i++)
{
	show_console_cursor(false);
	indicators::ProgressSpinner *spinner;
	
	spinner = new indicators::ProgressSpinner {
		option::PostfixText{ "Test" },
		option::ForegroundColor{ Color::yellow },
		option::SpinnerStates{ std::vector<std::string>{ "⠈", "⠐", "⠠", "⢀", "⡀", "⠄", "⠂", "⠁" } },
		option::FontStyles{ std::vector<FontStyle>{ FontStyle::bold } }
	};
	
	//free(spinner); // problem was here :(
	delete spinner;
	show_console_cursor(true);

	FreeHeap("Iteration");
		 
}

FreeHeap("After");

}
`