WWW and bytes issue with iOS (memory leak)?

I’m streaming data and using WWW to get the data… using the WWW.bytes data to FileStream to a file after it has completed downloading.

It seems that on iOS it is having some real issues with large files that are being streamed from the server… as long as the files are small (say, under a MB or so) it seems to cleanup fine with a .Dispose() and UnloadUnusedAssets()…

However, on larger files (say 40MB or larger)… I see in Xcode some memory warnings and even though I’m calling for release in code… it is not happening.

sample…

request = new WWW(url, null, headers);
yield return request;

if (request.bytes != null)
{
 byte[] file = request.bytes;
 request.Dispose();
 request = null;
 var filePath = Path.Combine(dataPath, fileName);
 FileStream output = File.Create(filePath);
 output.Write(file, 0, file.Length);
 output.Flush();
 output.Close();
 output.Dispose();
 output = null;
 filePath = null;
 file = null;
}

...
//cleanup with Resources.UnloadUnusedAssets();
GC.Collect();

I’m currently using Unity 5.3.2p4

is this a known bug and fixed in a later patch?

I found this from a while ago…:

as well as:

(which was ancient)

???

well… I changed it to use just File.WriteAllBytes(filePath,request.bytes);

with a dispose on WWW , UnloadUnusedAssets(), as well as a GC.Collect() and it still does not release… >.<

so, anyone else that has a problem with this… just DO NOT use WWW any longer.

I refactored to use WebClient and now things are working great…

and if anyone needs a reference, I found this to help with the exception handling (as I use an injected header for authorization checks): c# - Exception handling the right way for WebClient.DownloadString - Stack Overflow

and this lead me in the right direction:
http://stackoverflow.com/questions/29707709/downloading-large-file-in-unity3d-using-webclient
(Thank You Kimberly!)

why this is still buggy after a year or more of being reported is odd to me…

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

For more details, visit this blog