1

據我在xamarin中聲明視圖控制器中的全局變量是非常重要的,否則當涉及到綁定和所有涉及的時候它可以被垃圾收集。xamarin.ios中的內存管理問題

同樣對於通知,我們必須有一個nsobject類型的全局引用,並在我們不需要nsnotification時刪除nsobject。

有沒有實際的可用文檔,使原生的iOS開發者感到沮喪xamarin.ios

暗示一些東西像這將是任何iOS開發者誰成爲xamarin.ios開發者的好幫手

回答

0

在每個ViewControllers中輸入以下代碼:

public override void ViewDidDisappear (bool animated) 
{ 
    //Executed when we navigate to other view, moving this ViewController in Navigation stack 

    //1. UnSubscribe All Events Here (Note: These must be SubScribed back in ViewWillAppear) 
    btnLogin.TouchupInside -= OnLoginClicked 
    //2. Remove Any TapGuestures (Note: These must be added back in ViewWillAppear) 
    if (singleTapGuesture != null) 
    { 
     scrollView.RemoveGestureRecognizer(singleTapGuesture); 
     singleTapGuesture.Dispose(); 
     singleTapGuesture = null; 
    } 
    //3. Remove any NSNotifications (Note: These must be added back in ViewWillAppear) 
    //4. Clear anything here, which again initializes in ViewWillAppear 


    if (ParentViewController == null) { 
     //This section will be executed when ViewController is Removed From Stack 
     //1. Clear everything here 
     //2. Clear all Lists or other such objects 
     //3. Call Following Method which will clear all UI Components 
     ReleaseDesignerOutlets(); 
    } 
    base.ViewDidDisappear (animated); 
} 

當ViewController被導航或從堆棧中移除時,這將清除所有不需要的對象。

對於UITableViews,請使用WeakDataSource & WeakDelegate。

可以有很多更基於以下鏈接:

Ref 1

Ref 2