zoukankan      html  css  js  c++  java
  • WPF 内存泄漏方法定位

    总结来说:
    1、事件未注销
        解决方法:注意注销和清理这种事件。 A.Event-=处理函数
    2、数据绑定,由于绑定的属性不是DependencyProperty并且不是继承自INotifyPropertyChanged。
         经实验证明这种属性是不会自动更新的。
        解决方法:a、在绑定的时候注意标明BindingMode.OneTime
                       b、BindingOperations.ClearBinding(DependObject, DependObject Property)
     

      Binding  myDataBinding = new Binding("Children.Count");
     myDataBinding.Source = myGrid; 
     myDataBinding.Mode = BindingMode.OneWay;
     MyTextBlock.SetBinding(TextBlock.TextProperty, myDataBinding);

     3、Command绑定,这种泄漏方式和1极其类似
        解决方法: Window1.w1.CommandBindings.Remove(myCmdBinding);

    RoutedCommand    command = new RoutedCommand("ClearBox"this.GetType());
    command.InputGestures.Add(new KeyGesture(Key.F5));
    myCmdBinding = new CommandBinding(command, F5CommandExecute);
    Window1.w1.CommandBindings.Add(myCmdBinding); //add binding to Window 1

    4、静态事件

     
    5、其他的据说在目前的(.Net 3.5 SP1后期版本会修复),内存泄漏定位方法请阅读原文。就是图片的BitmapImage注意Freeze(),UriSource不要使用http://的形式(可以Down到本地目录进行使用)。
     
     
  • 相关阅读:
    Codeforces
    BZOJ
    BZOJ
    HDU
    Codeforces
    codeforces
    HDU-5441 Travel 离线-并查集
    codefoeces-1000E We Need More Bosses(tarjan+最长链)
    牛客网暑期ACM多校训练营(第五场)H-subseq 树状数组
    HDU-3533 Escape (BFS
  • 原文地址:https://www.cnblogs.com/wangn/p/3573856.html
Copyright © 2011-2022 走看看