question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Setting the Maximum value on a Trackbar to a very large number results in excessive memory usage

See original GitHub issue
  • .NET Core Version: 3.0 Preview1
  • Have you experienced this same bug with .NET Framework?: Yes

Problem description:
Setting the MaxValue on the Trackbar control to a very high number results in excessive ram usage (in the gigabytes for a very large number).

This appears to be because on initialization of the underlying windows control, the maximum is set before the tick mark frequency, resulting in it initializing excessive amounts of tickmarks, although I do not have the build configuration to verify this theory myself at this time as if I did, I would just verify and submit this as a PR. https://github.com/dotnet/winforms/blob/01eef03d8e0a6630076716b6cb08ed0a9def611a/src/System.Windows.Forms/src/System/Windows/Forms/TrackBar.cs#L893-L894

Actual behavior: Excessive ram is used (multiple gigabytes if compiled in x64)

Expected behavior: A reasonable amount of ram is used (assuming you set tickmarks to a reasonable number).

Minimal repro:
Within a form

TrackBar tb = new TrackBar();
tb.TickFrequency = 0; //Ensure no tickmarks should be drawn
tb.Maximum = 1000000000;
this.Controls.Add(tb);

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:31 (28 by maintainers)

github_iconTop GitHub Comments

1reaction
RussKiecommented, Nov 14, 2022

Maybe we need to tell the trackbar to repaint after setting the ticks.

If required, this can be done with Invalidate() call.

1reaction
JeremyKuhnecommented, Nov 14, 2022

As @RussKie mentioned, there is little chance that Windows will change anything here.

I took a quick look at the sources:

TBM_SETTICFREQ, TBM_SETRANGE, TBM_SETRANGEMIN, and TBM_SETRANGEMAX all set up an array with a DWORD entry for Max - Min - 1. It always reallocates on these messages if TBS_AUTOTICKS is set. The tick frequency has nothing to do with the size of the allocated array.

One could mitigate this slightly by combining MIN/MAX into RANGE, but you are kind of stuck outside of that. We should document that using the auto-tick setting shouldn’t be used with large max values. We can consider adding a feature for “user specified auto-ticks” in our control using the messages.

What I’d suggest is creating a derived control that manually draws and link or put the prototype here. We can look at what that entails and judge whether or not we want to try and merge that behavior in based on complexity and additional user feedback. Updating the docs is much easier and lower maintenance, and probably addresses the situation though.

I had hoped originally that the COMCTL implementation was smarter or gameable, but sadly that doesn’t seem to be the case.

Read more comments on GitHub >

github_iconTop Results From Across the Web

System.Windows.Forms.TrackBar memory use with a large ...
I have a control that contains a System.Windows.Forms.TrackBar. I was setting its maximum value to ~200,000,000. When I did this, the control ...
Read more >
Setting the Maximum value on a Trackbar to a very large ...
Use saved searches to filter your results more quickly · Setting the Maximum value on a Trackbar to a very large number results...
Read more >
TrackBar.Maximum Property (System.Windows.Forms)
The maximum value for the TrackBar. The default is 10. Examples. The following code example displays a form containing a TrackBar control and...
Read more >
Mvexpand memory usage- How do I troubleshoot this error?
Long story short, i got the error: warn : command.mvexpand: output will be truncated at 5200 results due to excessive memory usage. Memory...
Read more >
TrackBar.SetRange(Int32, Int32) Method
Sets the minimum and maximum values for a TrackBar. ... You can use this method to set the entire range for the TrackBar...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found