开发者

Windows Handle Issue

开发者 https://www.devze.com 2022-12-08 22:41 出处:网络
Facing an issue w开发者_开发问答here in the user objects goes more that 10000 in windows app and the app crashes.

Facing an issue w开发者_开发问答here in the user objects goes more that 10000 in windows app and the app crashes.

After much analysis we realized that we need to get rid of the panels that we use to align the controls and may be reduce the possibility of user objects reaching 10000.

Our App UI is dynamically generated driven by a configuration and it can vary. So all the UI generation is happening dynamically.

Any help would be much appreciated


This is an unfounded suggestion, but remember to make sure that unneeded Controls always detach themselves from events they are be subscribed to. A Control that's still subscribed to an event of an "active" (what's the right term?) object can't be cleaned up.


Just as a note, the Chrome development team hit this problem too, and the scroll bar arrows (among other things) weren't drawing anymore when some internal gdi limit was hit. It is quite possible to hit this limit in a complex enough gdi app.

You might want to do some research and see how they fixed it.

As an alternative, you could consider using a different platform, either gtk or wpf would do fine and they don't use gdi handles to draw.


from here,

If your program runs haywire, you will find that it manages to create about 10,000 window manager objects and then the system won't let it have any more. Why stop at 10,000?

The first answer is "If you have to ask, you're probably doing something wrong." Programs shouldn't be creating anywhere near ten thousands window manager objects in the first place.

There is no need for that many handles. I think you need a new solution.


I'm guessing this from your question, but you're probably putting this large number of controls on a scrollable panel or a tab control with multiple tab pages, which means that most of these controls aren't actually visible to the user at any given point in time (because they couldn't possibly all be visible at once).

If you have all of these controls on a scrollable panel, one possible solution is to only load and display the controls that are on the visible portion as the user scrolls around in the panel. As the user scrolls, you would unload and dispose the controls that are no longer visible.

If you have all of these controls in a multi-page tab control, you can use a similar strategy and only load the controls on a tab page when that page is made visible (and unload the controls from the previous top-most tab page at the same time).

Another general strategy is to break up your one monster form into a large number of UserControls, and only show one of these UserControls at a time.

0

精彩评论

暂无评论...
验证码 换一张
取 消