A memory surge issue
I'm not sure if this is a known issue, when I use ImPlot:: PlotLine to plot 80000 static points and display them all, for example:
static std::vector<float> plot_y(80000, 0);
if (ImPlot::BeginPlot(u8"test_plot1", u8"index", u8"val", ImVec2(-1, -1), ImPlotFlags_NoLegend | ImPlotFlags_NoTitle | ImPlotFlags_NoMouseText))
{
ImPlot::SetupAxis(ImAxis_Y1, u8"val", ImPlotAxisFlags_AutoFit);
ImPlot::SetupAxisLimits(ImAxis_X1, 0, 80000, ImGuiCond_Always);
ImPlot::PlotLine("plot2", plot_y.data(), 80000);
ImPlot::EndPlot();
}
The memory usage only increased by 25MB, which is basically normal. But when switching to dynamically drawing 80000 points, the memory usage will increase by more than 1000 MB, for example:
static std::vector<float> plot_y(80000, 0);
static int plot_show_points = 0;
plot_show_points += 200;
if (plot_show_points > 80000)
plot_show_points = 0;
if (ImPlot::BeginPlot(u8"test_plot1", u8"index", u8"val", ImVec2(-1, -1), ImPlotFlags_NoLegend | ImPlotFlags_NoTitle | ImPlotFlags_NoMouseText))
{
ImPlot::SetupAxis(ImAxis_Y1, u8"val", ImPlotAxisFlags_AutoFit);
ImPlot::SetupAxisLimits(ImAxis_X1, 0, plot_points, ImGuiCond_Always);
ImPlot::PlotLine("plot2", plot_y.data(), plot_show_points);
ImPlot::EndPlot();
}
How did you measure this?
I've just tried your code and looked at the VmSize: line of the /proc/<PID>/status and this is what I saw:
no plots : 95432 kB (imgui demo idling)
1st plot: 119880 kB (showing window with your plotting code no. #1)
2nd plot: 120064 kB (showing window with your plotting code no. #2)
For the second case the allocated memory gradually increases as more points are plotted, but does not go significantly above the amount of memory allocated in the first case. After >30 iterations of the plot loop the maximum allocated memory did not change a bit.
I also ran the same code under valgrind --tool=massif ./prog and visualized it. This is what I got:
1st case:
2nd case:
The usage looks pretty much comparable to me (there was only a single loop of the plotting performed in the second case.)
How did you measure this?
I've just tried your code and looked at the
VmSize:line of the/proc/<PID>/statusand this is what I saw:no plots : 95432 kB (imgui demo idling) 1st plot: 119880 kB (showing window with your plotting code no. #1) 2nd plot: 120064 kB (showing window with your plotting code no. #2)For the second case the allocated memory gradually increases as more points are plotted, but does not go significantly above the amount of memory allocated in the first case. After >30 iterations of the plot loop the maximum allocated memory did not change a bit.
I also ran the same code under
valgrind --tool=massif ./progand visualized it. This is what I got: 1st case:2nd case:
The usage looks pretty much comparable to me (there was only a single loop of the plotting performed in the second case.)
I'm glad you answered my question. I conducted the test on Win10 VS2022 and checked the application memory usage through the task manager.

