内存使用和导航的自定义控件问题
上面是我正在处理的自定义控件的图像。它实际上是窗口窗体中的三个独立的控件。它是一个容器控件,包含“平台/控制台”控件的多个实例。 “平台”控件包含“游戏”控件的多个实例。控制台是可折叠的,这将隐藏列表中的游戏。
现在我遇到的问题是,当一个人玩了3000个游戏时,内存使用量会上升到500MB左右,并且控制非常迟缓。现在我还没有优化应用程序线程的创建,但即使在创建之后它也是一头猪。
人们将如何释放已移出屏幕的控件的资源?有没有比测试每个控件以查看它是否位于某个可见区域更快的方法?我应该有不同的方式来设计这个控件吗?
我对 C# 没有广泛的了解,因此任何建议将不胜感激。
Above is an image for a custom control that I'm working on. It's actually three separate controls in a windows form. It's a container control which holds multiple instances of a "Platform/console" control. The "Platform" control holds multiple instances of a "Game" control. The consoles are collapsible which will hide the games in the list.
Now the problem I'm having is the fact that when a person has say 3000 game titles, the memory usage is up around 500MB, and the control is very sluggish. Now I haven't optimized the creation out of the application thread yet, but even after creation it's a pig.
How would a person go about freeing resources on controls that have moved off screen? Is there a quicker way than testing each control to see if it's in some visible area? Is there a different way I should be designing this control?
I don't have extensive knowledge in C# so any advice would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使控件“虚拟化”,您可能会减少内存占用。看一下 ListView,如果设置ownerDrawn = true 和 VirtualMode =true 且 VirtualListSize =3000,以下代码将创建项目(并存储它们)并进行自定义绘图。
您可能需要一些额外的编程,因为在您的所有者绘制的控件上没有任何东西是免费的......
If you make your Control "Virtualized" you might reduce the memory footprint. Have a look at ListView, if you set ownerDrawn = true and VirtualMode =true and VirtualListSize =3000 the following code will create items (and store them) and do custom drawing.
You might be in for some extra programming because on your owner drawn control nothing comes for free...