Note that there are some explanatory texts on larger screens.

plurals
  1. POReduce memory footprint of File operations
    primarykey
    data
    text
    <p>I'm trying to run this method, it works fine but every time after some hundreds of internal iterations I get with an Out of Memory exception:</p> <pre><code>... MNDBEntities db = new MNDBEntities(); var regs = new List&lt;DOCUMENTS&gt;(); var query = from reg in db.DOCUMENTS where reg.TAG_KEYS.Any(p =&gt; p.TAG_DATE_VALUES.FirstOrDefault().TAG_DATE_VALUE.HasValue &amp;&amp; p.TAG_DATE_VALUES.FirstOrDefault().TAG_DATE_VALUE.Value.Year == 2012) select reg; var pages = new List&lt;string&gt;(); foreach (var item in query) { Document cert = new Document(); var tags = item.TAG_KEYS; foreach (var tag in tags) { // Basic stuff... } var pagesS = item.PAGES; foreach (var page in pagesS) { var path = @"C:\Kumquat\" + (int)page.NUMBER + ".vpimg"; File.WriteAllBytes(path, page.IMAGE); pages.Add(path); Console.WriteLine(path); } //cms.Save(cert, pages.ToArray()).Wait(); foreach (var pageFile in pages) File.Delete(pageFile); pagesS = null; pages.Clear(); } ... </code></pre> <p>I'm pretty sure problem is related with the File.WriteAllBytes or the File.Delete because if I comment those lines the method runs without exception. What I'm doing is basically get some tags from a DB plus a document image, that image is then saved onto disk then a stored into a cms and then deleted from disk. Honestly don't figure out what I'm doing wrong with that File calls. Any idea?</p> <p>This is what PerfView shows:</p> <p><img src="https://i.stack.imgur.com/rFTZn.png" alt="PerfView of the method"></p> <p>This is what visual studio 2012 profiler shows as the hot point, the thing is: this is all generated code (within the Entity Model) am I doing something wrong maybe with the properties of the model?</p> <p><img src="https://i.stack.imgur.com/CdPAF.png" alt="enter image description here"></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload