在CONSOLE中输入tasks,help等指令后,调用free查看剩余内存发现递减。
而free指令本身不会造成内存泄漏
IDF中的CONSOLE组件内存泄漏
Re: IDF中的CONSOLE组件内存泄漏
This is due to the way console history feature works.
When new command is typed, and the command is not the same as the previous command, it is added to history. If it is the same as the previous command, it is not added to history. Adding a command to history requires allocating memory for the command string (strdup). Therefore:
free <- gets added to history, allocate 5 bytes (actual heap size is reduced by 12 bytes due to metadata and alignment)
-> (reports heap value)
free <- does not get added to history, because is the same as last command
-> (reports same heap value)
But
free <- gets added to history, allocate 5 bytes, heap is reduced by 12 bytes
-> reports heap value (after the allocation)
help <- gets added to history, allocate 5 bytes, heap is reduced by 12 bytes
-> prints help
free <- gets added to history, allocate 5 bytes, heap is reduced by 12 bytes
-> reports heap value, which is less than the previous one by 24 bytes (due to the last two allocations)
None of these strings are leaked, though. When the history buffer becomes full, old items will be deleted. They will also be deleted if you call linenoiseHistoryFree().
If you don't wish to store history, you can disable it using CONFIG_STORE_HISTORY.
When new command is typed, and the command is not the same as the previous command, it is added to history. If it is the same as the previous command, it is not added to history. Adding a command to history requires allocating memory for the command string (strdup). Therefore:
free <- gets added to history, allocate 5 bytes (actual heap size is reduced by 12 bytes due to metadata and alignment)
-> (reports heap value)
free <- does not get added to history, because is the same as last command
-> (reports same heap value)
But
free <- gets added to history, allocate 5 bytes, heap is reduced by 12 bytes
-> reports heap value (after the allocation)
help <- gets added to history, allocate 5 bytes, heap is reduced by 12 bytes
-> prints help
free <- gets added to history, allocate 5 bytes, heap is reduced by 12 bytes
-> reports heap value, which is less than the previous one by 24 bytes (due to the last two allocations)
None of these strings are leaked, though. When the history buffer becomes full, old items will be deleted. They will also be deleted if you call linenoiseHistoryFree().
If you don't wish to store history, you can disable it using CONFIG_STORE_HISTORY.
Who is online
Users browsing this forum: Bing [Bot] and 167 guests