ioscordovadidreceivememorywarningviewdidunload

Cordova iOS custom Plugin : handle memory warning


I'm developing an iOS app that use cordova(2.1), and some custom plugins.

The problem that I'm trying to face is the following : When I show my plugin(basically a camera plugin with more features than the built-in cordova plugin) sometime I receive a memory warning and a consequent unload of the view containing the webview. This is a really huge issue for me because once my imagePicker is dismissed the webview is not restored.

I had a look at the CDVCamera plugin source and what I noted is this :

(1) the plugin save the webview :

 // we need to capture this state for memory warnings that dealloc this object
    cameraPicker.webView = self.webView;

here I don't understand what's going on, ok we save the webview in case after a memory warning it will be unloaded, but I can't figure it out how/where in the framework the webview is restored.

(2) The plugin use a Bool property called hasPendingOperation, this property If I understood is used by the CDVViewController when a memory warning is received to avoid purging the memory if a plugin is active.

The first things that I don't understand is the following why when my controller receive a memory warning the supercontroller(CDVViecontroller) don't receive it?

Second is it possible to apply the pattern used by the CDVCamera plugin in conjunction with the CDVViewController to handle memory warnings in custom plugins?

Any helps in manage memory warnings with cordova to avoid the webview to be unloaded will be appreciated.


Solution

    1. That was probably a legacy use where we need to keep a reference to the webView to write javascript to it when the picker was dismissed. Not really needed because we are using a different way to write back to the webview: https://github.com/apache/cordova-ios/blob/0a978a6617c58bfa98968e0c6bdcdb4f10f01902/CordovaLib/Classes/CDVCamera.m#L301

    2. Not sure what you mean, the CDVViewController does receive the memory warning as well, and queries each plugin's hasPendingOperation property. If it is set to true, the plugin is not deallocated. Note that the iOS watchdog may kill the app anyway if memory is not sufficiently released.