0

I have a such simple code:

// cache is disabled 
[OutputCache(NoStore = true, Duration = 0)]
public async Task<ActionResult> GetVideo(string path)
{            
    byte[] data = await _fileService.GetFileAsync(path);                        
    if (data == null)
        return HttpNotFound();

    return File(data, "video/mp4");
}

This code is very simple: it retrieves file's content as byte array and sends it to client. I have a web page that contains some video tags. All of those tags use GetVideo as source. Each video is about 400-500 Mb. After page is ready w3wp.exe in Task Manager takes 3-4 Gb RAM and doesn't release memory. As I wrote previously I disable resutl caching with OutputCacheAttribute. The problem doesn't hide in method GetFileAsync because when I replace line

byte[] data = await _fileService.GetFileAsync(path);      

with line

byte[] data = System.IO.File.ReadAllBytes(Server.MapPath(path));

this problem still exists. Maybe anyone knows how to release memory after sending bytes to client?

Pupkin
  • 1,211
  • 3
  • 13
  • 30
  • Why are you reading all bytes in memory to begin with? Web servers are great in streaming from disk without having to read the entire file into memory. That approach also speeds up the initial page load by _seconds_. – CodeCaster Sep 12 '17 at 13:22
  • @CodeCaster I want to use streaming later but now I wonder why memory is not released. And is it possible to stream data from database? – Pupkin Sep 12 '17 at 13:34
  • Anyway what did your research show? What happens when you request another page after this? Does the memory use increase, or will the allocated memory be reused? See also [.NET Free memory usage (how to prevent overallocation / release memory to the OS)](https://stackoverflow.com/questions/9805058/net-free-memory-usage-how-to-prevent-overallocation-release-memory-to-the-os). – CodeCaster Sep 12 '17 at 13:35

0 Answers0