title: EF6 + SQLite + Code First Out of Memory exception
body: <p>I use <code>Entity framework 6</code> and <code>SQLite</code> + <code>Code First</code>
  And I get <code>Out of Memory exception</code> in following code, though I am freeing all memory.</p>
  
  <p>If I uncomment the next line does not show any error.</p>
  
  <p><code>System.Windows.Forms.MessageBox.Show("");</code></p>
  
  <p>Does anyone have an explanation for this?
  Are COM communication to SQLITE depends on Wimdows Messages?</p>
  
  <pre><code>using SQLite.CodeFirst;
  using System;
  using System.Collections.Generic;
  using System.Data.Entity;
  using System.Threading;
  using System.Windows;
  
  namespace SQLiteDemo
  {
      public partial class MainWindow : Window
      {
          public MainWindow()
          {
              InitializeComponent();
  
              List&lt;Node&gt; list = new List&lt;Node&gt;();
              for (int i = 0; i &lt; 700000; ++i)
              {
                  list.Add(new Node() { Id = i, Name = i.ToString() });
              }
              AddListToTree(list);
          }
  
          private void AddListToTree(List&lt;Node&gt; list)
          {
              TreeDbContext db = new TreeDbContext();
              db.Tree.Load();
  
              var transaction = db.Database.BeginTransaction();
              int Counter = 0;
  
              foreach (var node in list)
              {
                  Counter += 1;
                  if (Counter % 100000 == 0)
                  {
                      // the magic here 
                      System.Windows.Forms.MessageBox.Show("");
                  }
                  db.Database.ExecuteSqlCommand(
                      "INSERT INTO [Nodes]([Name], [Order], [Type], [Parent_Id]) VALUES (@p0, @p1, @p2, @p3);",
                      node.Name, node.Order,
                      node.Type,
                      node.Parent == null ? (object)DBNull.Value : node.Parent.Id);
              }
              transaction.Commit();
              transaction.Dispose();
              db.Dispose();
          }
      }
  
      class Node
      {
          public int Id { get; set; }
          public string Name { get; set; }
          public Node Parent { get; set; }
          public int Order { get; set; }
          public byte Type { get; set; }
      }
  
      class TreeDbContext : DbContext
      {
          public TreeDbContext()
              : base("MyDbContextDB")
          { }
  
          protected override void OnModelCreating(DbModelBuilder modelBuilder)
          {
              var sqliteConnectionInitializer = new SqliteCreateDatabaseIfNotExists&lt;TreeDbContext&gt;(modelBuilder);
              Database.SetInitializer(sqliteConnectionInitializer);
          }
  
          public DbSet&lt;Node&gt; Tree { get; set; }
      }
  }
  </code></pre>