- Home /
iPad crashes after many WWW images queries
Hi, I'm experiencing some problems with memory warnings on an iPad3 when downloading images from the web. I have to download a lot of images (200-300 at half of the device resolution) one after another (using a coroutine an waiting that an image has been downloaded before starting with the next) from a third party service and I store the WWW return data in an ArrayList. Unfortunately the iPad often crashes (but not always), sometimes it gets memory warnings and then crashes while other times it just crashes without any warning.
I know I'm downloading a lot of data, but I was wondering if there's a workaround or if there's a way to store those WWW images data in a better way and avoid memory warnings.
Thanks
Answer by whydoidoit · Jun 19, 2013 at 09:33 AM
Save them as files to your Application.persistentDataPath and do www.Dispose() after each image. Open the images when you need them.
yield return www;
System.IO.File.WriteAllBytes(Application.persistentDataPath + "/" + someFileName, www.bytes);
www.Dispose();
Hi, thanks for the answer. I unfortunately get an error when I try to use the image:
You are trying to load data from a www stream which had the following error when downloading. Couldn't open file /Users/Robin/Library/Caches/$$anonymous$$yProject/imgNr1.jpeg
After executing:
WWW imgData = new WWW("file://" + Application.persistentDataPath + "/imgNr"+frontImgFrame+".jpeg");
yield return imgData;
imgData.LoadImageIntoTexture(imgFront);
You can use Texture2d's LoadImage and File.ReadAllBytes
sorry I had a typo in my code...now it works. It's a bit slow when I have to retrieve the images one after another fast...also I still get the memory warning and the crash :(
You won't be able to keep many of those images in memory at a time - they take 2x the size of the uncompressed image (ignore the size of the jPeg). So a 1024x1024 is around 8$$anonymous$$B of ram.
Use StartCoroutine(Resources.UnloadUnusedAssets()) to remove some.
Your answer
Follow this Question
Related Questions
Patch/Update ios App 0 Answers
load level problem when building to ipad 2 Answers
What in my stats makes the game crash on web or iPad 1 Answer
WWW random freezes 1 Answer