Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by sdnj · Feb 12, 2015 at 12:16 PM · androidioswwwmemorydownload

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

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<string> downloadableMovies;
 
     public void StartDownload(List<string> 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) 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 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, 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.

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image DeveshPandey · Jun 27, 2017 at 05:42 PM 0
Share

Check this nice blog, working perfectly for big files downloading http://unitydevelopers.blogspot.in/2017/06/large-file-downloader-for-unity3d.html

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by sdnj · Feb 13, 2015 at 05:24 PM

Yesterday's Unity Patch 4.6.2p2 fixed the System.Net.Socket incompatibility with iOS 64-bit builds. My solution based on this Unity Answer using sockets now works fine and I will be able to submit my app to the store next week. I'm still not sure whether the memory problem with the www-class is a known issue or not, maybe I will send a bug report to Unity.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image DeveshPandey · Jan 14, 2018 at 08:51 AM 0
Share

Here is the great plugin to download any small/big files without memory leak.

https://www.assetstore.unity3d.com/#!/content/92128?aid=1101l34jr

For more details, visit this blog

http://unitydevelopers.blogspot.in/p/blog-page_13.html

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Memory management theory question 1 Answer

Why do textures take double memory on iOS and Android devices? 1 Answer

Handheld.PlayFullScreenMovie() works on Android but not iOS? 2 Answers

Can I load textures at runtime with a smaller memory footprint? 1 Answer

How to apply downloaded textures on Android/iOS 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges