NativeScript / plugins

@nativescript plugins to help with your developments.
https://docs.nativescript.org/plugins/index.html
Apache License 2.0
190 stars 108 forks source link

Memory Allocation Issue #70

Closed sspark3 closed 3 years ago

sspark3 commented 3 years ago

Environment { "@angular/animations": "~10.1.4", "@angular/common": "~10.1.4", "@angular/compiler": "~10.1.4", "@angular/core": "~10.1.4", "@angular/forms": "~10.1.4", "@angular/platform-browser": "~10.1.4", "@angular/platform-browser-dynamic": "~10.1.4", "@angular/router": "~10.1.4", "@nativescript/angular": "10.1.4", "@nativescript/background-http": "^5.0.1", "@nativescript/camera": "^5.0.2", "@nativescript/core": "~7.1.0", "@nativescript/imagepicker": "^1.0.2", "@nativescript/theme": "~2.5.0", "@nativescript/types": "^7.0.4", "@nstudio/nativescript-checkbox": "^2.0.4", "nativescript": "^7.1.2", "nativescript-background-fetch": "^1.2.1", "nativescript-bitmap-factory": "^1.8.1", "nativescript-download-progress": "^1.2.0", "nativescript-mediafilepicker": "^4.0.1", "nativescript-pdf-view": "^2.0.1", "nativescript-ui-listview": "^9.0.4", "nativescript-webview-interface": "^1.4.3", "reflect-metadata": "~0.1.10", "rxjs": "~6.6.0", "tns-ios": "^6.5.2", "tslib": "1.10.0", "zone.js": "~0.11.1" }, "devDependencies": { "@angular-devkit/core": "~10.1.4", "@angular/cli": "~10.1.4", "@angular/compiler-cli": "~10.1.4", "@nativescript/ios": "7.1.1", "@nativescript/webpack": "~4.0.0", "@ngtools/webpack": "~10.1.4", "typescript": "~3.9.0" }

Describe the bug I created an app where users create checklists and upload images for different items. I am using imagepicker to accomplish this. With the latest iOS version, we noticed users experiencing crashing when uploading multiple images. Taking a deeper look, we saw memory was capping out causing the crashing. When the saveToFile function is called, it allocates memory to save, and then never releases it. When that line is commented out, the behavior is expected; memory goes up when the image is uploaded, and then goes right back down.

Code Associated

selectImages() {

let context = imagepicker.create({
  mode: "multiple",
  maximumNumberOfSelection: 10
});

context.authorize().then(() => {
  return context.present();
}).then((selection) => {

  const documents: Folder = <Folder>knownFolders.documents();
  const folder: Folder = <Folder>documents.getFolder("photos");
  let running = false;
  selection.forEach((selected) => {

    var newImage:ImageSource;
    ImageSource.fromAsset(selected).then((res) => {
      newImage = res;
      let newPath = folder.path + "/cameraPic_" + (new Date()).getTime();
      let newPathThumbnail = newPath + "_thumbnail.jpeg"
      newPath = newPath + ".jpeg";
      let photoJson = {path: "file://" + newPath,thumb: "file://" + newPathThumbnail}

      newImage.saveToFile(newPath,"jpeg");

      running = false;
    });        
  });
});

}

rigor789 commented 3 years ago

Duplicate of #71