Project: titanium
Issue TIMOB-19981: iOS: FileStream Significant memory leak while reading/writing files using FileStream
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: {code} 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; } {code} This is how the file is written: {code} 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;	} {code} In both cases the heap grows until the app crashes. I've attached an image which shows how the heap grows.
Story points: 5