Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-25744

iOS: Uploaded file persists in memory when using JSCore

    Details

    • Story Points:
      8
    • Sprint:
      2018 Sprint 06 SDK, 2018 Sprint 07 SDK, 2018 Sprint 08 SDK, 2018 Sprint 09 SDK, 2018 Sprint 10 SDK, 2018 Sprint 11 SDK

      Description

      Doing a file upload with the createHTTPClient on iOS in TI SDK 7.x.x causes the file to stay in ram after the upload is completed or aborted. It does not get removed from ram as it should. When doing a large upload or multiple uploads this is a rather big problem because it can cause the app to crash or have a large ram usage as you can see from the screen shot.

      Example code is below, using a 100MB file will cause 400 + Mb of ram usage for 1 upload, this will then stay in ram, doing 3 uploads will cause the app to crash on a iPhone X.

      The file should be removed from ram when the upload is completed or aborted, it use to do this in previous version of TI.

      var xhr = null;
       
      var win = Ti.UI.createWindow({
        backgroundColor: '#fff',
        fullscreen: false, navBarHidden: true, exitOnClose: true, theme: "Theme.materialTheme", orientationModes: [Titanium.UI.PORTRAIT]
      });
       
      var runTime = Ti.UI.createLabel({
        text: 'Run Time...',
        top: 50,
        left: 10,
        color: '#000'
      });
       
      var uploadSpeed = Ti.UI.createLabel({
        text: '0.00 Mbps',
        top: 90,
        left: 10,
        color: '#000'
      });
       
       
      var buttonStart = Ti.UI.createButton({ title: "START", width: 100, height: 40, top: '45%', left: '10%' });
      var buttonStop = Ti.UI.createButton({ title: "STOP", width: 100, height: 40, top: '45%', right: '10%' });
       
      var uploadfile = Ti.Filesystem.getFile(Ti.Filesystem.getResourcesDirectory(), "100MB.bin").read();
       
      buttonStart.addEventListener("click", function() {
       
        console.log('Starting Upload');
       
        var startTime = new Date().getTime();
        var totalPercent = 0;
       
        xhr = Titanium.Network.createHTTPClient();
        xhr.onsendstream = function(e){ 
            console.log(e.progress);
       
            totalPercent = (e.progress).toFixed(2);
            var currentTime = new Date().getTime();
            var timeDiff = ((currentTime-startTime)/1000).toFixed(2);
            var totalDownloaded = (102400 * totalPercent);
            var currentKBPS = (((((totalDownloaded * 1024) * 8.192) / timeDiff) / 1024 / 1024)).toFixed(2);
       
            runTime.text = timeDiff;
            uploadSpeed.text = currentKBPS + ' Mbps';
        };
       
        xhr.onload = function(e) {
       
        };
        xhr.open('POST','http://sfo.veeapps.com/upload.php');
        xhr.send({media: uploadfile });
        
      });
       
       
      buttonStop.addEventListener("click", function() {
        xhr.abort();
        xhr = null;
      });
       
       
      win.add(runTime);
      win.add(uploadSpeed);
      win.add(buttonStart);
      win.add(buttonStop);
      win.open();
      

        Attachments

          Activity

            People

            • Assignee:
              hknoechel Hans Knöchel
              Reporter:
              dlewis23 Donovan Lewis
              Reviewer:
              Vijay Singh
            • Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Backbone Issue Sync

                • Titanium SDK/CLI <> Titanium Mobile
                  Synced with:
                  TIMOB-6150
                  Sync status:
                  ERROR
                  Last received:
                  Last sent:

                  Git Source Code