3

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 required 800MB of memory. Reducing the maximum value to 2,000,000 used a more reasonable amount of memory.

//trackBar.Maximum = 210554060;  // uses ~800MB of memory
trackBar.Maximum = 1000000;      // uses a small amount of memory

Is this a bug in the Windows control? Or am I asking the trackbar to do something unreasonable?

Update: I've created a new Windows Form project with nothing but a trackbar on the form. I set the maximum value to 200,000,000. I set the TickFrequency and changes so that there are not millions of ticks and change steps.

When I do this, the application uses over 800MB of memory. I am using .NET Framework 4.

trackbar max set to 200,000,000, using > 800MB memory.

Update I found somewhat of an explanation for this problem: http://www.tech-archive.net/Archive/DotNet/microsoft.public.dotnet.framework.windowsforms.controls/2006-12/msg00015.html

Adding link to test project https://www.dropbox.com/s/nh6jsymw05feoqn/testingTrackbar.zip?m

GreenRibbon
  • 299
  • 2
  • 16
  • How did you determine that it uses a huge amount of memory? – Immortal Blue Mar 04 '13 at 19:45
  • @ImmortalBlue: See [this post](http://stackoverflow.com/questions/15206654/excessive-memory-usage-by-comctl32-dll-when-a-checkbox-controls-visible-becomes) As far as narrowing it down to the TrackBar, I changed the trackbar's maximum to 1000000 and used the Resource Monitor tool to view Commit memory. I suppose I should make sure the problem isn't something else using that maximum value. – GreenRibbon Mar 04 '13 at 19:55
  • Well, I've just done a noddy reproduction, and the maximum size makes no difference at all to my app. I doubt therfore that it's actually the trackbar that's using that much memory. Have you bound something to the trackbar maximum value? – Immortal Blue Mar 04 '13 at 20:02
  • @ImmortalBlue I've reproduced in a new project and have the same result. See the update. – GreenRibbon Mar 04 '13 at 20:39
  • Can you post the project (with compiled exe) somewhere to see if we can reproduce on another setup? – Immortal Blue Mar 04 '13 at 21:11
  • A very interesting point here, when I made an app to reproduce this, I couldn't. (I added an obscenely large trackbar as outlined here to an existing scratch project). Today, I start up said project, and it's cripplingly slow and large. How odd that restarting visual studio makes the issue show itself! Although not surprising reading @Hans Passant answer! – Immortal Blue Mar 06 '13 at 20:47

1 Answers1

5

Is this a bug in the Windows control?

Yes, I think you can call that a bug. Particularly nasty on a 64-bit operating system with the platform target set to AnyCPU so there's no reasonable upper-bound on the memory allocation. My machine completely died a swapping death with mouse and Ctrl+Alt+Del unresponsive, I hard-booted it to get it back. Thanks.

Two bugs actually. It starts with the native track bar control not putting a reasonable upper limit on the number of ticks. You can survive that in design mode by assigning the properties in the right order. But it is compounded by a flaw in the TrackBar class wrapper, it assigns the Maximum property before the TickFrequency property when it initializes the native control at runtime. So for a brief moment it still has a gazillion ticks. Well, it is not brief when it is 2 billion of them, like I unwittingly tried.

No simple fix for this and this bug isn't going to get fixed. Use reasonable values, you can always map them by multiplication.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536