when to release objects in mono touch / mvvmcross

前端 未结 2 979
太阳男子
太阳男子 2020-12-17 06:20

We are implementing an app which seems to have major memory leaks. For an example we have a view with its corrosponding viewmodel that is registered 38 times in the mono pro

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-17 07:14

    A good rule is that containees that are added to NSObject-based classes should only reference containers using WeakReference objects.

    Like this:

     // MyView is a UIView, which is an NSObject, so the rule will apply here
     class MyView : UIView {
           WeakReference myController;
    
           public MyView (RectangleF bounds, UIViewController myContainer) 
               : base (bounds) {
               this.myController = myContainer;
           }
     }
    

提交回复
热议问题