title: Memory leak when using time in NHibernate SQL query
body: <p>I use NHibernate in my ASP.NET application to connect to an MS SQL Server 2005 database. In some cases I need to write my own SQL queries. However, I noticed that the SQL server thread leaks about 50 KB of memory every time I execute the following piece of code:</p>
  
  <pre><code>NHibernate.ISession session = NHibernateSessionManager.Instance.GetSession();
  
  ISQLQuery query = session.CreateSQLQuery(
    "select {a.*} from t_alarm a where a.deactivationtime &gt; '" +
    DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss") +
    "'");
  
  query.AddEntity("a", typeof(TAlarm));
  System.Collections.IList aList = query.List();
  </code></pre>
  
  <p>When I look in Windows task manager I see that the process <code>sqlservr.exe</code> increases its memory usage by 50 KB each time I run this code.</p>
  
  <p>Here is the really interesting part. If I, in the code above, replace <code>"yyyy-MM-dd HH:mm:ss"</code> with <code>"yyyy-MM-dd HH:mm"</code> (i.e. I remove the seconds) the memory leaks stop.</p>
  
  <p><em>Update: Apparently the memory leaks doesn't actually stop. They just show once a minute instead. Presumably when the SQL query changes.</em></p>
  
  <p>The returned results are the same in both cases.</p>
  
  <p>Does anyone have a clue what is going on here?</p>