Uploaded image for project: 'Apache Cordova'
  1. Apache Cordova
  2. CB-9652

Cordova File plugin memory leaking

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 3.5.0
    • Fix Version/s: None
    • Component/s: cordova-plugin-file
    • Labels:

      Description

      We are creating apps using Ionicframework, then building them using cordova. What we are doing in our app is taking photos using Cordova Camera, then moving the files to specific directory. The user has an ability to upload all photos taken to server. Here is how the user progresses through the app:

      1. Make Photo using Cordova Camera.
      2. Use Cordova File to move created file using step 1 to other location.
      3. Repeat process 1&2 several times (20 times approx).
      4. Start sync process
      5. $http requests start (synchronous, not asynchronous!)
      5.1. Read data from File as base64 string (using Cordova File plugin)
      5.2. Send data to server
      5.3. On success, use Cordova File to delete photo from device.

      This was tested on:

      • iPad mini (ios 8, uiwebview)
      • iPad 4 (ios 8, uiwebview)

      We've debugged the whole process through Xcode and checked how memory management is doing. The results were catastrophic!

      • After each File.moveTo call, the app memory grew for at least 5MB.
      • After each File.readAsDataUrl call, the app memory grew for at least 5MB.
      • After each File.removeFile call, the app memory grew for at least 5MB.

      015-09-02 09:00:03.487 test_app[1409:279018] THREAD WARNING: ['File'] took '84140.372803' ms. Plugin should use a background thread.
      2015-09-02 09:00:51.925 test_app[1409:279018] THREAD WARNING: ['File'] took '11.680908' ms. Plugin should use a background thread.
      2015-09-02 09:00:58.376 test_app[1409:279018] THREAD WARNING: ['File'] took '11.557861' ms. Plugin should use a background thread.
      2015-09-02 09:01:12.505 test_app[1409:279018] THREAD WARNING: ['File'] took '12.233887' ms. Plugin should use a background thread.
      2015-09-02 09:01:26.748 test_app[1409:279018] THREAD WARNING: ['File'] took '11.616943' ms. Plugin should use a background thread.
      2015-09-02 09:01:33.780 test_app[1409:279018] THREAD WARNING: ['File'] took '11.599121' ms. Plugin should use a background thread.
      2015-09-02 09:01:54.696 test_app[1409:279018] THREAD WARNING: ['File'] took '11.628174' ms. Plugin should use a background thread.
      2015-09-02 09:02:01.838 test_app[1409:279018] THREAD WARNING: ['File'] took '11.617920' ms. Plugin should use a background thread.
      2015-09-02 09:02:08.800 test_app[1409:279018] THREAD WARNING: ['File'] took '13.183105' ms. Plugin should use a background thread.
      2015-09-02 09:02:15.660 test_app[1409:279018] THREAD WARNING: ['File'] took '11.779053' ms. Plugin should use a background thread.
      2015-09-02 09:02:29.399 test_app[1409:279018] THREAD WARNING: ['File'] took '10.287842' ms. Plugin should use a background thread.
      2015-09-02 09:02:43.206 test_app[1409:279018] THREAD WARNING: ['File'] took '11.649170' ms. Plugin should use a background thread.
      2015-09-02 09:02:50.500 test_app[1409:279018] THREAD WARNING: ['File'] took '11.527100' ms. Plugin should use a background thread.
      2015-09-02 09:02:57.189 test_app[1409:279018] THREAD WARNING: ['File'] took '11.545166' ms. Plugin should use a background thread.
      2015-09-02 09:03:03.999 test_app[1409:279018] THREAD WARNING: ['File'] took '11.493164' ms. Plugin should use a background thread.
      2015-09-02 09:03:15.452 test_app[1409:279018] Received memory warning.
      2015-09-02 09:03:19.132 test_app[1409:279018] Received memory warning.
      2015-09-02 09:03:20.488 test_app[1409:279018] Received memory warning.
      2015-09-02 09:03:20.527 test_app[1409:279018] Received memory warning.
      2015-09-02 09:03:20.556 test_app[1409:279018] Received memory warning.
      2015-09-02 09:03:20.584 test_app[1409:279018] Received memory warning.
      2015-09-02 09:03:20.610 test_app[1409:279018] Received memory warning.
      2015-09-02 09:03:24.390 test_app[1409:279018] Received memory warning.
      2015-09-02 09:03:24.408 test_app[1409:279018] Received memory warning.
      2015-09-02 09:03:26.034 test_app[1409:279018] Received memory warning.
      2015-09-02 09:03:26.489 test_app[1409:279018] Received memory warning.
      2015-09-02 09:03:26.509 test_app[1409:279018] Received memory warning.
      2015-09-02 09:03:26.529 test_app[1409:279018] Received memory warning.
      2015-09-02 09:03:26.549 test_app[1409:279018] Received memory warning.
      2015-09-02 09:03:26.570 test_app[1409:279018] Received memory warning.
      2015-09-02 09:03:26.601 test_app[1409:279018] Received memory warning.
      2015-09-02 09:03:26.656 test_app[1409:279018] Received memory warning.
      2015-09-02 09:03:26.689 test_app[1409:279018] Received memory warning.
      2015-09-02 09:03:26.720 test_app[1409:279018] Received memory warning.
      2015-09-02 09:03:26.749 test_app[1409:279018] Received memory warning.
      2015-09-02 09:03:26.773 test_app[1409:279018] Received memory warning.
      2015-09-02 09:03:26.806 test_app[1409:279018] Received memory warning.
      2015-09-02 09:03:34.164 test_app[1409:279018] THREAD WARNING: ['File'] took '14.667969' ms. Plugin should use a background thread.
      2015-09-02 09:03:35.344 test_app[1409:279018] Received memory warning.
      2015-09-02 09:03:35.653 test_app[1409:279018] Received memory warning.
      2015-09-02 09:03:35.674 test_app[1409:279018] Received memory warning.
      2015-09-02 09:03:35.696 test_app[1409:279018] Received memory warning.
      2015-09-02 09:03:35.718 test_app[1409:279018] Received memory warning.
      2015-09-02 09:03:35.743 test_app[1409:279018] Received memory warning.
      2015-09-02 09:03:35.769 test_app[1409:279018] Received memory warning.
      2015-09-02 09:03:35.807 test_app[1409:279018] Received memory warning.
      2015-09-02 09:03:35.844 test_app[1409:279018] Received memory warning.
      2015-09-02 09:03:35.886 test_app[1409:279018] Received memory warning.
      2015-09-02 09:03:35.954 test_app[1409:279018] Received memory warning.
      2015-09-02 09:03:41.163 test_app[1409:279018] THREAD WARNING: ['File'] took '12.062012' ms. Plugin should use a background thread.
      2015-09-02 09:03:41.256 test_app[1409:279018] Received memory warning.
      2015-09-02 09:03:41.262 test_app[1409:279018] Received memory warning.

      The problem isn't when we have just a few files to move (aka 5), but having approximately 50 files, it always leads to an app crash. On iPad mini, after 10 or 15 images, on iPad4, after 30, 40 or 50 images.

      We've also tried to update Objective C code at all functions which we were using surrounding them with

      @autoreleasepool

      brackets. It didn't helped.

      We've also tried to upgrade Cordova, tried to use different File plugin versions, but there wasn't any difference. You kinda start thinking,.. is it actually any good using those unoptimized plugins? Has anyone actually tried them constantly running without closing the app? Has anyone actually thought the clients also use old devices?

      There isn't any memory management to be done on the app side, since we're coding in JS (using Angular). But the crashes... well... we're dissapointed to found out it will take few years before we'll have enough memory and the Cordova itself won't be such an resource hog.

      Is there actually anything we can do to 'optimize' the calls? Sadly, there's no File.clean() or File.recycle() function we could use to clean the cordova plugin memory.

      What are your suggestion?

      Regards,

      Gregor

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              lordgreg Gregor
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: