Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You are not calling Dispose on your Image instances. Also create your image once and then extract your data.</p> <p>See also: </p> <p><a href="http://msdn.microsoft.com/en-us/library/8th8381z.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/8th8381z.aspx</a></p> <p><strong>EDIT</strong> If copied your code and tested it with my Picture Library. My avg. FileSize is 2-3 MB per File. I've executed your program and it did exactly what it should. The GC did exactly what I've expected. </p> <p>Memory of your Program was always about 11-35 MB Private Working set, Commit Size was stable at 43 MB. </p> <p>I've aborted the program after 1156 files with a total picture size of 2.9 GB. </p> <p><strong>So there must be another reason for you out of memory exception.</strong></p> <p>Here's my program output and code:</p> <pre><code>1133: Total Size = 2.842,11 MB 1134: Total Size = 2.844,88 MB 1135: Total Size = 2.847,56 MB 1136: Total Size = 2.850,21 MB 1137: Total Size = 2.853,09 MB 1138: Total Size = 2.855,86 MB 1139: Total Size = 2.858,59 MB 1140: Total Size = 2.861,26 MB 1141: Total Size = 2.863,65 MB 1142: Total Size = 2.866,15 MB 1143: Total Size = 2.868,52 MB 1144: Total Size = 2.870,93 MB 1145: Total Size = 2.873,64 MB 1146: Total Size = 2.876,15 MB 1147: Total Size = 2.878,84 MB 1148: Total Size = 2.881,92 MB 1149: Total Size = 2.885,02 MB 1150: Total Size = 2.887,78 MB 1151: Total Size = 2.890,57 MB 1152: Total Size = 2.893,55 MB 1153: Total Size = 2.896,32 MB 1154: Total Size = 2.898,92 MB 1155: Total Size = 2.901,48 MB 1156: Total Size = 2.904,02 MB </code></pre> <p>Sourcecode:</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; using System.Drawing; namespace SharpLibrary_MediaManager { public abstract class BaseFile { public string Name { get; set; } public string FileType { get; set; } public long Size { get; set; } public DateTime CreationDate { get; set; } public DateTime ModificationDate { get; set; } public abstract void getFileInformation(string filePath); } public class Picture : BaseFile { public int Height { get; set; } public int Width { get; set; } public Image Thumbnail { get; set; } public override void getFileInformation(string filePath) { FileInfo fileInformation = new FileInfo(filePath); using (var image = Image.FromFile(filePath)) { if (fileInformation.Exists) { Name = fileInformation.Name; FileType = fileInformation.Extension; Size = fileInformation.Length; CreationDate = fileInformation.CreationTime; ModificationDate = fileInformation.LastWriteTime; Height = image.Height; Width = image.Width; Thumbnail = image.GetThumbnailImage(40, 40, null, new IntPtr()); } } } } class Program { static void Main(string[] args) { string folderPath = @"C:\Users\arthur\Pictures"; DirectoryInfo folder = new DirectoryInfo(folderPath); List&lt;Picture&gt; lol = new List&lt;Picture&gt;(); double totalFileSize = 0; int counter = 0; foreach (FileInfo x in folder.GetFiles("*.jpg", SearchOption.AllDirectories)) { Picture p = new Picture(); p.getFileInformation(x.FullName); lol.Add(p); totalFileSize += p.Size; Console.WriteLine("{0}: Total Size = {1:n2} MB", ++counter, totalFileSize / 1048576.0); } foreach (var p in lol) { Console.WriteLine("{0}: {1}x{2} px", p.Name, p.Width, p.Height); } } } } </code></pre>
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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