c# - Dispose image and memory stream objects after calling HttpContext.Response.OutputStream.Write() -


how improve code below in terms of better performance? example, must explicitly dispose both memorystream , image objects after calling outputstream.write()?

any improvement on other areas, e.g. buffer , memorystream allocation?

the code allow web user download png file. part of below:

outputimage(image); image.dispose(); ...  public void outputimage(image image){     using(memorystream temp = new memorystream()){        image.save(temp, imageformat.png)        byte[] buffer = temp.getbuffer();        context.response.outputstream.write(buffer, 0, temp.length);                   } } 

asp.net, .net 4.5

response.outputstream getbuffer

response.outputstream memorystream

memorystream


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

reflection - How to access the object-members of an object declaration in kotlin -

php - Doctrine Query Builder Error on Join: [Syntax Error] line 0, col 87: Error: Expected Literal, got 'JOIN' -