<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      享受代碼,享受人生

      SOA is an integration solution. SOA is message oriented first.
      The Key character of SOA is loosely coupled. SOA is enriched
      by creating composite apps.
        博客園  :: 首頁  :: 新隨筆  :: 聯系 :: 訂閱 訂閱  :: 管理

      Memory leak caused by EventHandle - weak event

      Posted on 2010-06-04 16:48  idior  閱讀(2443)  評論(5)    收藏  舉報

      When using normal C# events, registering an event handler creates a strong reference from the event source to the listening object.

      If the source object has a longer lifetime than the listener, and the listener doesn't need the events anymore when there are no other references to it, using normal .NET events causes a memory leak: the source object holds listener objects in memory that should be garbage collected.


      An article in codeproject provides various patterns for resolving the memory leak caused eventhandle.

      1.  Dispose pattern. Unhook the event handler in dispose method.

      Disadvantages: Explicit memory management is hard, code can forget to call Dispose.

       

      2.    Use an event wrapper.

      This solution moves the event handling code into a wrapper class that forwards the calls to a listener instance which is referenced with a weak reference. This weak reference allows for easy detection if the listener is still alive.

      Disadvantages : Leaks the wrapper instance when the event never fires.

       

      3.      WPF WeakEventManager.

      WPF has built-in support for listener-side weak events, using the WeakEventManager class. It works similar to the previous wrapper solutions, except that a single WeakEventManager instance serves as a wrapper between multiple sender and multiple listeners. Due to this single instance, the WeakEventManager can avoid the leak when the event is never called: registering another event on a WeakEventManager can trigger a clean-up of old events. These clean-ups are scheduled using the WPF dispatcher, they will occur only on threads running a WPF message loop. 

      Also, the WeakEventManager has a restriction that our previous solutions didn't have: it requires the sender parameter to be set correctly, otherwise the source cannot be found in the listener's code.

      Disadvantages: Tied to a WPF dispatcher, cannot be easily used on non-UI-threads.

       

       

      A long thread in WPF-Disciples holds a discussion on a potential bug in RelayCommand. Nathan Nesbit though WPF’s CanExecuteChanged Implementation was Wrong.

       

      The RelayCommand directly registers the CanExecuteChanged event handler with the CommandManager.RequestSuggested event.  The MSDN docs say that the CommandManager.RequestSuggested only holds a weak reference to the handler, so shouldn't the RelayCommand also keep a strong reference to the delegate to avoid it being collected?   

       

      The answer is that we should either keep a strong reference to the delegate on Command Source or Listener. WPF keeps the delegate on Command Source which are Button, MenuItem and etc.

      Check out the second line of HookCommand method which defined in ButtonBase:

      代碼
      private void HookCommand(ICommand command)
      {
          EventHandler handler = new EventHandler(this.OnCanExecuteChanged);
          CanExecuteChangedHandler.SetValue(this, handler);
          command.CanExecuteChanged += handler;
          
      this.UpdateCanExecute();
      }


       

      Delay's blog talks about how to use SOS and gcroot to diagnose memory leak.


       

      招聘廣告,道富信息科技和網新恒天都招聘.NET高級開發人員和架構師。需要對.NET和面向對象設計有比較深入的了解和較好的英文讀寫能力,如果有 WPF 或Silverlight開發經驗更佳,工作地點杭州。簡歷請發至 nxu  [at] statestreet [dot] com。
      主站蜘蛛池模板: 将乐县| 人妻少妇邻居少妇好多水在线| 国产精品香蕉在线观看不卡| 武功县| 狠狠综合久久av一区二| 亚洲三级香港三级久久| 国产精品v片在线观看不卡| 中文字幕无码av激情不卡 | 无码精品人妻一区二区三区中| 人人爽人人爽人人片av东京热| 一本一道av中文字幕无码| 亚洲国产精品人人做人人爱| 国产福利在线观看免费第一福利| 成人做爰视频www| 欧美精品一产区二产区| 无码人妻一区二区三区精品视频| 中文字幕在线亚洲精品| 上饶县| 亚洲乱色一区二区三区丝袜| 久久精品不卡一区二区| 十八禁在线观看视频播放免费| 中文字幕乱码十国产乱码| 九九热在线精品视频首页| 九九热在线免费播放视频| 国产成人高清精品亚洲| 亚洲最大的成人网站| 成年黄页网站大全免费无码| 国产成人午夜福利院| 激情伊人五月天久久综合| 国产成人免费高清激情视频| 强奷乱码欧妇女中文字幕熟女| 中文字幕国产日韩精品| 国产99视频精品免费专区| 国产女人和拘做受视频免费| 午夜福利电影| 国产中文字幕一区二区| 亚洲精品亚洲人成在线| 激情综合网一区二区三区| 色成年激情久久综合国产| 成av免费大片黄在线观看| 综合久青草视频在线观看|