Quantcast
Channel: Questions in topic: "ios"
Viewing all articles
Browse latest Browse all 4709

OutOfMemoryException when downloading files via the www class (iOS and Android)

$
0
0
Hello, I am currently trying to build an app with a new feature for mobile platforms (iOS and Android). The added feature consists of downloading a list of movies (up to 60). At first glance, using the www class to download movies seemed to work fine on all platforms but unfortunately, an OutOfMemoryException occurs after downloading several movies. On iOS this occurs after downloading approximately 6-16 movies (the file size varies between 10 and 50 MB). Since I have read about other people having similar problems with downloading "large" files, the size may be relevant. I am using Unity 4.6.2p1 and testing the app on an iPad3 and 4 (iOS 8.1.3) as well as on a Samsung Note 10.1 (2014 Edition) (Android 4.3). Please see the relevant code below: public class MovieController{ WWW www; List downloadableMovies; public void StartDownload(List movies){ downloadableMovies = movies; StartCoroutine("DownloadMovies"); } IEnumerator DownloadMovies() { int i = 1; foreach(string fileName in downloadableMovies){ www = new WWW(url+"/"+videoInfos[id].basename+movieExtension); yield return www; if (www != null && string.IsNullOrEmpty(www.error) && www.isDone) { FileStream stream = new FileStream(Application.persistentDataPath+ "/"+ fileName, FileMode.Create); try{ stream.Write(www.bytes, 0, www.bytes.Length); } catch(Exception ex){ DeleteMovie(fileName); // delete incomplete file yield break; } finally{ stream.Close(); stream.Dispose(); stream = null; } } www.Dispose(); www = null; i++; } } } Obviously there has been a known memory leak issue on iOS prior to Unity 4.6.1 (see the [issue tracker][1]) but since I am using a newer version, this should have been resolved. I have already tried using a "using" statement and have added Dispose-calls for both the www and Stream instances. After several time-consuming rebuilds and tests on iOS, I even tried implementing another download solution using the System.Net.Sockets library based on [this Unity Answer][2] but that doesn't seem to work with the 64-bit version for iOS (required since Feb 1st). Are there any mistakes in my code that I am oblivious of? Or can anybody confirm that using the www class for downloading files causes memory problems? If the alternative socket solution does currently not work with 64-bit iOS builds, what else could? Any help would be much appreciated. EDIT: I uploaded the [iOS log][3], in case that may prove helpful. EDIT 2: I also tried downloading the movies via the WebClient API which is currently not functioning, see [the Unity blog][4]. [1]: http://issuetracker.unity3d.com/issues/memory-leak-in-www-class-on-ios [2]: http://answers.unity3d.com/questions/322526/downloading-big-files-on-ios-www-will-give-out-of.html [3]: http://en.file-upload.net/download-10290328/OutOfMemoryException_iOS_log.txt.html [4]: http://blogs.unity3d.com/2015/01/29/unity-4-6-2-ios-64-bit-support/

Viewing all articles
Browse latest Browse all 4709

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>