MonoTouch - WebRequest memory leak and crash?

坚强是说给别人听的谎言 提交于 2019-11-30 21:41:24

I think you should read in your file 1 KB (or some arbitrary size) at a time and write it to the web request.

Code similar to this:

byte[] buffer = new buffer[1024];
int bytesRead = 0;
using (FileStream fileStream = File.OpenRead("YourFile.txt"))
{
    while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) != 0)
    {
        httpPostStream.Write(buffer, 0, bytesRead);
    }
}

This is off the top of my head, but I think it's right.

This way you don't have an extra 3MB floating around in memory when you don't really need to. I think tricks like this are even more important on iDevices (or other devices) than on the desktop.

Test the buffer size too, a larger buffer will get you better speeds up to a point (I remember 8KB being pretty good).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!