2

アプリケーションで UIWebView を使用していますが、使用しているメモリを解放できないようです。UIWebViewを保持するView ControllerをロードするUIButtonがあります。webView が読み込まれると、Real Memory (Instruments を使用してチェック) が上昇しますが、解放しようとしても低下しません。

ボタンを押すと:

if (childBroswer != null)

        {
            childBroswer.Dispose();
            childBroswer = null;
        }

        childBroswer = new ChildBrowser(url);

        AppDelegate d = (AppDelegate)UIApplication.SharedApplication.Delegate;

        if ( d.rootNavigationController.RespondsToSelector(
            new MonoTouch.ObjCRuntime.Selector("presentViewController:animated:completion:")))
        {
                d.rootNavigationController.PresentViewController(childBroswer, true, null);
        }
        else
        {
            d.rootNavigationController.PresentModalViewController(childBroswer, true);
        }

子ブラウザ クラス:

 public partial class ChildBrowser : UIViewController
{
    public string _url {get;set;}
    UIActivityIndicatorView activityIndicator;
    UIWebView webBrowser;
    NSUrl nsURL;
    NSUrlRequest nsURLRequest;
    public ChildBrowser (string url) : base ("ChildBrowser", null)
    {
        nsURL = new NSUrl(url);
        nsURLRequest = new NSUrlRequest(nsURL);
    }

    public override void DidReceiveMemoryWarning ()
    {
        // Releases the view if it doesn't have a superview.
        base.DidReceiveMemoryWarning ();

        // Release any cached data, images, etc that aren't in use.
    }

    public override void ViewDidLoad ()
    {
        base.ViewDidLoad ();

        if (webBrowser == null)
        {
            webBrowser = new UIWebView(new RectangleF(0,41,320,380));
        }

        this.Add(webBrowser);

        webBrowser.LoadFinished += (object sender, EventArgs e) => {
            activityIndicator.StopAnimating();
        } ;

        webBrowser.LoadStarted += (object sender, EventArgs e) => {

            if (activityIndicator == null)
            {
                activityIndicator = new  UIActivityIndicatorView(new RectangleF(UIScreen.MainScreen.Bounds.Width / 2 - 50,
                                                                                UIScreen.MainScreen.Bounds.Height / 2 - 30,100,100));
                activityIndicator.Color = UIColor.Black;
            }

            activityIndicator.StartAnimating();
            this.Add(activityIndicator);
        } ;

        webBrowser.LoadHtmlString("<html><head></head><body></body></html>",null);   //stringByEvaluatingJavaScriptFromString:@"document.body.innerHTML = \"\";"];
        webBrowser.LoadRequest(nsURLRequest);

        closeBrowser.TouchUpInside +=  handleClose;


        // Perform any additional setup after loading the view, typically from a nib.
    }

    private void handleClose(object sender, EventArgs e)
    {
        webBrowser.Delegate = null;
        webBrowser.StopLoading();
        webBrowser.Dispose();

        DismissViewController(true,delegate {
            closeBrowser.TouchUpInside -=  handleClose;
            webBrowser.RemoveFromSuperview();
            this.Dispose();
        } );
    }

    public override void ViewWillAppear (bool animated)
    {
        base.ViewWillAppear (animated);


    }

    public override void ViewDidDisappear(bool animated)
    {
        base.ViewDidDisappear(true);
        //webBrowser.RemoveFromSuperview();
    }

    public void webViewDidFinishLoad(UIWebView webView)
    {
        //string u = "";
    }

    protected override void Dispose(bool disposing) 
    {
        ReleaseDesignerOutlets();
        base.Dispose(disposing);
    }

私は何が欠けていますか?

ありがとうございました!

4

2 に答える 2