Reputation: 3048
I am wondering how does one correctly dispose a webview so that you only have one instance of it at any given time? At the moment each time I open a webview I can see it in my chrome debugging tools. Aside from this using up memory, this is also leading to an issue where the webview displays content incorrectly as it appears to be trying to load one after the other until it finally hits the final webview it has.
I tried disposing of it as such:
protected override void Dispose(bool disposing) {
webView.Dispose();
webView = null;
base.Dispose(disposing);
}
Of course, given my problem, does not appear to be working. My webview sits inside of a UIViewController which in itself is sitting inside of another one. My understanding of dispose is that once the UIViewController is no longer shown on the screen, the dispose method should be called on it (theoretically).
Upvotes: 1
Views: 930
Reputation: 6641
Why do you want to release the webView
manually? From this documentation, we know that for UIViewController if it pops from the navigation stack and any managed object references that this object holds are also disposed or released. Dispose
method will be invoked automatically and all of its subViews will be released too. There's no need to call that in Dispose(bool disposing)
manually.
My webview sits inside of a UIViewController which in itself is sitting inside of another one.
Do you mean the UIViewController
may contain several webViews, and you want to release one at some time you want? Try:
webView.RemoveFromSuperview();
webView = null;
Upvotes: 3