# onDestroyed(\_:)

Runs `handler` once this view closes, with [`DocumentEnd.closing`](<https://rasmuskard.github.io/react-native-minimal-webview/swift/documentation/minimalwebview/documentend/closing/index.md>), the only reason it gets on iOS.

```
func onDestroyed(_ handler: @escaping (DocumentEnd) -> Void)
```

## Discussion

It comes after the [`onDocumentEnd(_:)`](<https://rasmuskard.github.io/react-native-minimal-webview/swift/documentation/minimalwebview/webviewcontext/ondocumentend(_-)/index.md>) handlers that get `closing`. The WKWebView has stopped loading, paused its media, lost every script message handler (yours too) and left the view by then, but is still alive, and the context does nothing.

Clean up here: what `attach` set up on the WKWebView, such as an observation or a swapped class.
