I have prepared a Custom Camera Plugin for iOS and Android because the default one does not provide the functionality I need.
What I want to achieve is retrieving images from the camera in the background without displaying a preview frame so that they can be requested from the Javascript and used directly in the HTML or posted in Base64 by HTTP POST. (+ a few other things that are not ready yet :))
I’ve actually managed and I have uploaded my plugin here:
Things are working as expected on Android but I have a problem on iOS (probably a memory leak).
It works for 3-4 minutes, the memory is increasing and suddently it stops refreshing (the app is still alive, the Camera object also).
Since ARC is enabled, I cannot manually release/dispose some of the objects myself. I have tried to wrap some places that were looking strategic with @autoreleasepool { }, memory usage is slightly better but the issue is still here.
I was wondering if there is an Objective C specialist out there who could have a look at my plugin and maybe provide some advises on how to fix this or at least locate where it comes from.
I have the feeling that it’s the fact of calling the plugin every 50-100ms to retreive an image that consumes the memory and doesn’t release it (the returned stream is between 8kb and 2Mb depending on the resolution):
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:base64String];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
But even by stopping the refresh and the camera the memory never gets released even when CPU usages get lower.
In order to hopefully motivate somebody to have a look at the code, I have prepared a simple and ready-to-use Ionic project here:
After grabbing this normally, all you have to do it:
cordova platform add ios (or android)
ionic build ios (or android)
Maybe there is a better approach. Suggestions are welcome anyway
I have realized (of course after creating my own) that I wasn’t the first one with this idea but looking at the existing variants didn’t help me to solve this problem.
The ones I’ve tried apparently have similar memory issues.
I have found those:
https://github.com/daraosn/Cordova-CanvasCamera (iOS only)
https://github.com/mbppower/CordovaCameraPreview (iOS + Android)
https://github.com/Clark-Nikdel-Powell/realtime_camera (iOS only, interesting variant that doesn’t need to call the plugin for every frame but trigs a callback in javascript multiple time directly from the Objective C side but I think that his approach didn’t work since it’s disabled in the code )
Thanks in advance.