Hi team,
On android, I’m downloading and saving several videos, unfortunately sometime (it’s not consistent) the Memory Mono, start to grow and doesn’t get free, even after:
www.Dispose();
www = null;
Resources.UnloadUnusedAssets();
GC.Collect();
I’m removing the previous video file and transition to an empty scene before loading a new video, but it doesn’t help the Memory Mono, so after a couple of videos loaded, I still run out of memory.
Any idea? Could it be a limitation on how much data can it be written per session?
Not sure if this will work but you could try using the ‘using’ functionality of C# which automatically calls the Dispose functionality on your objects. It also keeps it within local scope.
Thanks for the idea. I end up using WebClient.
For dealing with large amounts of memory, it is best to use streams:
There are various kinds of streams.
WebClient deals with streams as well, just make sure to utilize streams primarily.
Interesting. I haven’t get yet, how to implement it, and what would be the advantage.
Currently I’m downloading using:
client = new WebClient();
client.DownloadFileCompleted += DownloadFileCompletedHandler;
client.DownloadFileAsync(new Uri(strURL), write_path);
Then call my video player with:
player.Load("file://" + write_path);
And delete the file when needed:
System.IO.File.Delete(write_path);
It seems to work fine. But of course I’m curious about your “system.io.stream” idea, so please feel free to guide me a bit more, and I’ll be happy to do some test.
Thanks a lot!
Well WebClient.DownloadFileAsync(string,string) that you call is streaming the file to the file location you supply. So the memory overhead is not an issue there. It works like a stream would.
File.Delete is not memory intensive at all, so it’s of no concern.
I don’t know what the ‘player.Load’ actually is, I have no idea what type ‘player’ is, so I couldn’t say anything about it.
But as I said in my previous post, WebClient is a viable option because it tends to work with streams for memory conservance.
Thanks Lordofduct for sharing your impressive expertise. It’s good to know that I’m on the right path, and will do some research on my end to have a better understanding on how the webclient and stream work.
For clarification, the ‘player’ is just a video player that load the file from the persistentDataPath - so all good here.
To extend the topic a bit, I’m wondering if it would be possible to have the video downloading to the device, even if the app is closed, like they do in some video app such as Vrse or MilkVr.
Thanks again!