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

A memory surge issue #589

Open
zhubo1126 opened this issue Aug 30, 2024 · 1 comment
Open

A memory surge issue #589

zhubo1126 opened this issue Aug 30, 2024 · 1 comment

Comments

@zhubo1126
Copy link

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();
				}

@hinxx
Copy link

hinxx commented Sep 11, 2024

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:
Screenshot_2024-09-11_09-21-06

2nd case:
Screenshot_2024-09-11_09-22-03

The usage looks pretty much comparable to me (there was only a single loop of the plotting performed in the second case.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants