title: Loading big amount of images (OutOfMemory Exception). How to load Images directly from HDD?
body: <p>I'm trying to load big amount of images as a DataSource for GridApp template. I use recursive function to walk trough folders:</p>
  
  <pre><code>public async void walk(StorageFolder folder)
      {
          IReadOnlyList&lt;StorageFolder&gt; subDirs = null;
          subDirs = await folder.GetFoldersAsync();
          foreach (var subDir in subDirs)
          {
              await SampleDataSource.AddGroupForFolderAsync(subDir.Path);
              walk(subDir);
          }
      }
  </code></pre>
  
  <p>And here is the core function:</p>
  
  <pre><code>public static async Task&lt;bool&gt; AddGroupForFolderAsync(string folderPath)
      {
          if (SampleDataSource.GetGroup(folderPath) != null) return false;
          StorageFolder fd = await StorageFolder.GetFolderFromPathAsync(folderPath);
          IReadOnlyList&lt;StorageFile&gt; fList1 = await fd.GetFilesAsync();
          List&lt;StorageFile&gt; fList2 = new List&lt;StorageFile&gt;();
          foreach (var file in fList1)
          {
              string ext = Path.GetExtension(file.Path).ToLower();
              if (ext == ".jpg" || ext == ".png" || ext == ".jpeg") fList2.Add(file);
          }
          if (fList2.Count != 0)
          {
              var folderGroup = new SampleDataGroup(
                  uniqueId: folderPath,
                  title: fd.Path,
                  subtitle: null,
                  imagePath: null,
                  description: "Description goes here");
              foreach (var i in fList2)
              {
                  StorageFile fl = await StorageFile.GetFileFromPathAsync(i.Path);
                  IRandomAccessStream Stream = await fl.OpenAsync(FileAccessMode.Read);
                  BitmapImage pict = new BitmapImage();
                  pict.SetSource(Stream);
                  if (pict != null &amp;&amp; folderGroup.Image == null)
                  {
                      folderGroup.SetImage(pict);
                  }
                  var dataItem = new SampleDataItem(
                      uniqueId: i.Path,
                      title: i.Path,
                      subtitle: null,
                      imagePath: pict,
                      description: "Decription goes here",
                      content: "Content goes here",
                      @group: folderGroup);
                  folderGroup.Items.Add(dataItem);
              }
              AllGroups.Add(folderGroup);
              return true;
          }
          else { return false; }
      }
  </code></pre>
  
  <p>I need to load a real big amount of files ( 164 folders and more than 1300 files, 500 MB at all). Later this amount could be bigger. It seems like IRandomAccessStream loads files into RAM. How to load images to app directly from HDD? Is it possible for Windows-Store Apps? Is it possible to do it still asynchronously?</p>
  
  <p>I understand that my code needs re-factoring. I'm not asking to re-write it. I only need an advice how to save memory in this situation.</p>