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

iOS: FileStream Significant memory leak while reading/writing files using FileStream

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Critical
    • Resolution: Invalid
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: iOS
    • Environment:
    • Story Points:
      5
    • Sprint:
      2015 Sprint 25 SDK

      Description

      PROBLEM:

      When you want to read or write a file using FileStream.read(buffer) and FileStream.write(buffer), the memory used to store the data read/written is leaked, leading to a crash after writing/reading files for a few minutes.

      TEST CASE:

      This is how the file is read:

      while (true) {
      		
      		var file = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, "image.png");
      		var fileStream = file.open(Ti.Filesystem.MODE_READ);
      		var buffer = Ti.createBuffer({
      			length: 1024 * 10
      		});
      		
      		while (fileStream.read(buffer) > 0) {}
      		
      		file = null;
      		fileStream.close();
      		fileStream = null;
      		buffer.release();
      		buffer = null;
      }

      This is how the file is written:

      while (true) {
      		
      		var file = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, "output.txt");
      		var fileStream = file.open(Ti.Filesystem.MODE_WRITE);
      		var buffer = Ti.createBuffer({
      			value: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut nisi felis, ultrices nec blandit vitae, efficitur a lacus. Nunc nec neque eleifend, aliquam leo id, scelerisque dolor. Suspendisse potenti. Pellentesque feugiat volutpat dictum. Morbi et massa venenatis lectus sodales maximus. In id ornare justo. Duis a nulla tincidunt, laoreet leo nec, aliquam ex. Nunc condimentum tellus justo, non efficitur magna viverra sit amet. Sed lectus neque, placerat non posuere in, faucibus quis nisl. Aliquam lobortis est eget felis varius, a placerat ex interdum. Aenean sit amet tempor turpis. Fusce at faucibus nisi. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Phasellus lacus enim, efficitur eget egestas vitae, viverra vel neque. Donec orci lacus, consectetur sit amet placerat vel, pharetra nec odio. Quisque tempus nulla diam, id aliquet tellus pharetra et. Pellentesque id urna non nisi commodo aliquam. Praesent nec porttitor metus, ac finibus purus. Curabitur vel magna libero. Duis cursus diam sapien, eu finibus erat rutrum sed. Fusce viverra dictum erat cursus finibus. Maecenas lobortis neque libero, et porttitor tortor tincidunt eu. Mauris commodo interdum urna ac egestas. Fusce vehicula egestas risus et efficitur. Suspendisse nisl ex, sagittis nec neque vitae, malesuada vulputate justo. Vivamus aliquet lorem tellus, et convallis felis sollicitudin a. Vestibulum non lacus ut metus placerat feugiat vel sit amet nunc. Pellentesque vestibulum, turpis nec feugiat tincidunt, arcu lorem iaculis felis, eget mattis arcu nunc non mi. Phasellus eros erat, condimentum nec varius ac, eleifend non tortor. Nunc pellentesque purus non lorem ultrices rhoncus. Integer in efficitur dolor. Aenean laoreet et dolor placerat accumsan."
      		});
      		
      		var bytesWritten = 0;
      		while (bytesWritten < 1024*1014) {
      			bytesWritten += fileStream.write(buffer);
      		}
      		
      		file = null;
      		fileStream.close();
      		fileStream = null;
      		buffer.release();
      		buffer = null;
      		
      	}

      In both cases the heap grows until the app crashes. I've attached an image which shows how the heap grows.

        Attachments

          Activity

            People

            • Assignee:
              penrique Pedro Enrique (Inactive)
              Reporter:
              tola.ware Fernando Manzano
            • Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Backbone Issue Sync

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

                  Git Source Code