具有矩形的WPF 4.0 Canvas占用大量内存 [英] WPF 4.0 Canvas with rectangles consuming lots of memory

查看:389
本文介绍了具有矩形的WPF 4.0 Canvas占用大量内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

推荐答案

  • 我认为您不应该调用这三个InvalidateXXX-Methods.
    至少要消耗它们,建议不要显式调用它们
    尤其是当您也最终调用UpdateLayout时.
  • 如果不为每个矩形创建一个新的Brush而是重用,您将获得一点记忆力
    预定义的静态"Brushes.Red"
  • 将容量减少到4会导致在添加下一个重新摆放时隐式地将容量再次加倍,达到8.
    因此,在动态情况下,它可能无法节省内存.
  • 高度为2的矩形框的StrokeThickness为2,StrokeThickness 1足够了.
  • 对RemoveRange的调用通过了无效的计数值,计数应少4.
  • I think you shouldn't call the three InvalidateXXX-Methods.
    they are at least perf consuming at it's recommended not to call them explicitly
    especially when you also call UpdateLayout finally.
  • You will gain a little memory if you don't create a new Brush foreach rect but rather reuse
    the predefined static "Brushes.Red"
  • Reducing capacity to 4 will cause capacity to be doubled up to 8 again implicitly when the next reatangle is added.
    So in a dynamic scenario it's probably not saving memory.
  • How can a retcangle with height and width of 2 have StrokeThickness of 2, StrokeThickness 1 is enough.
  • The call to RemoveRange passes an invalid value for count, count should be 4 less.
MainCanvas.Children.RemoveRange(4, MainCanvas.Children.Count - 4);
                        

  • 考虑通过维护矩形池来重用矩形.
  • Chris


    这篇关于具有矩形的WPF 4.0 Canvas占用大量内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆