title: System.OutOfMemoryException occurs frequently after Upgrading SQL Server 2016 to version 13.0.15700.28
body: <p>I am running Windows 10 Pro 64 bit on a dev box that has multiple monitors, 16 gigs DDR4 RAM, 4 Ghz I7, GTX 970.  I run SQL Management Studio with SQL Server 2016 Developer Edition along with VS 2015 Enterprise Update 3. </p>
  
  <p>Yesterday I upgraded Sql Management Studio 2016 to 13.0.15700.28 and it was like a poison pill for my machine.  Now after an hour or two it will throw an out of memory except:</p>
  
  <blockquote>
    <p>An error occurred while executing batch. Error message is: Exception
    of type 'System.OutOfMemoryException' was thrown</p>
  </blockquote>
  
  <p>Now this is sometimes typical if you are doing very large return sets of over a few million rows.  NOT if you are doing</p>
  
  <pre><code>Select Top 10 * from SmallObject
  </code></pre>
  
  <p>I was doing some new table and procedure creation for new objects to an existing development system.  And this just occurs out of the blue for no rhyme or reason.  It also appears to be a partial blocking error for SSMS as it now freezes the system and attempts to bring up a connection dialog window like I am first starting SSMS and attempting to connect to a datasource.  Thus far it goes to a crawl until I kill it from task manager.  I am also running Redgate's SQL Prompt 7.2.0.241.  Things I have tried:</p>
  
  <ol>
  <li>Attempted to keep tabs under five at a time and close them as I am done.</li>
  <li>Do not break off the tabs from one screen to another.</li>
  <li>Turn off Redgate and see if it is the culprit</li>
  <li>Check memory use as I go</li>
  </ol>
  
  <p>I know it blew up last night as I came into work and SSMS let me know it had crashed.  This may be an MS bug but there may be a bug in Redgate or some other config I have so I thought it best to ask SO and see what others have seen.  This build of SSMS is as of 8/15/2016 so it is very new.</p>
  
  <p>Two errors from stack traces of Application Event Logs: Event 1026</p>
  
  <blockquote>
    <p>Application: ssms.exe Framework Version: v4.0.30319 Description: The
    process was terminated due to an unhandled exception. Exception Info:</p>
    
    <p>System.ComponentModel.Win32Exception at
    System.Windows.Forms.NativeWindow.CreateHandle(System.Windows.Forms.CreateParams)
    at System.Windows.Forms.Control.CreateHandle() at
    System.Windows.Forms.ComboBox.CreateHandle() at
    System.Windows.Forms.Control.CreateControl(Boolean) at
    System.Windows.Forms.Control.CreateControl(Boolean) at
    System.Windows.Forms.Control.CreateControl(Boolean) at
    System.Windows.Forms.Control.CreateControl(Boolean) at
    System.Windows.Forms.Control.CreateControl(Boolean) at
    System.Windows.Forms.Control.CreateControl() at
    System.Windows.Forms.Control.WmShowWindow(System.Windows.Forms.Message
    ByRef) at
    System.Windows.Forms.Control.WndProc(System.Windows.Forms.Message
    ByRef) at
    System.Windows.Forms.ScrollableControl.WndProc(System.Windows.Forms.Message
    ByRef) at
    System.Windows.Forms.Form.WmShowWindow(System.Windows.Forms.Message
    ByRef) at
    System.Windows.Forms.Form.WndProc(System.Windows.Forms.Message ByRef)
    at
    System.Windows.Forms.Control+ControlNativeWindow.OnMessage(System.Windows.Forms.Message
    ByRef) at
    System.Windows.Forms.Control+ControlNativeWindow.WndProc(System.Windows.Forms.Message
    ByRef) at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr,
    Int32, IntPtr, IntPtr)</p>
  </blockquote>
  
  <p>The other one was an event log 1002 error 'Application Hang' and has no real meaningful help that I can see:</p>
  
  <blockquote>
    <p>
    Ssms.exe 
    2015.130.15700.28 
    68ac 
    01d1f98d17a32d16 
    4294967295 
    C:\Program Files (x86)\Microsoft SQL Server\130\Tools\Binn\ManagementStudio\Ssms.exe 
    62a64950-658b-11e6-a2c8-f832e4a07fda 
     
    </p>
    
    <p>54006F00700020006C006500760065006C002000770069006E0064006F0077002000690073002000690064006C00650000000000</p>
    
    <p></p>
  </blockquote>
  
  <p><strong>Updated 8-23-2016:</strong></p>
  
  <p>Still get this error from time to time:</p>
  
  <blockquote>
    <p>The program Ssms.exe version 2015.130.15700.28 stopped interacting
    with Windows and was closed. To see if more information about the
    problem is available, check the problem history in the Security and
    Maintenance control panel.  Process ID: 35f8  Start Time:
    01d1fca7e48da2da  Termination Time: 4294967295  Application Path:
    C:\Program Files (x86)\Microsoft SQL
    Server\130\Tools\Binn\ManagementStudio\Ssms.exe  Report Id:
    4e8b6ab9-693f-11e6-a2cb-f832e4a07fda  Faulting package full name:<br>
    Faulting package-relative application ID:</p>
  </blockquote>
  
  <p>Clearly this is an issue for people other than me as I am getting votes on it here:
  <a href="https://connect.microsoft.com/SQLServer/feedback/details/3062914/system-outofmemoryexception-thrown-by-even-small-selects-randomly-now" rel="noreferrer">https://connect.microsoft.com/SQLServer/feedback/details/3062914/system-outofmemoryexception-thrown-by-even-small-selects-randomly-now</a></p>
  
  <p>If you have this happen to you or know a potential fix, please let me know.  At this point if I have to do heavy SQL work coming up I am thinking of downgrading at this point.  Again I am on Windows 10 64 bit machine and this only happened after upgrading to the most recent SSMS build.</p>
  
  <p><strong>Update 8-24-2016</strong></p>
  
  <p>MS appears to acknowledge this bug now.  If you have this happen to you PLEASE go to this link and upvote:
  <a href="https://connect.microsoft.com/SQLServer/feedback/details/3074856" rel="noreferrer">https://connect.microsoft.com/SQLServer/feedback/details/3074856</a></p>
  
  <p><strong>Update 8-31-2016</strong></p>
  
  <p>Latest from MS on exception:</p>
  
  <blockquote>
    <p>Posted by Microsoft on 8/29/2016 at 10:21 AM turns out there's a
    thread leak in a utility class. The number of threads leaked will be
    proportional to the number of registered servers you have, among other
    things. A fix is coming in the next release</p>
  </blockquote>
  
  <p>I downgraded as doing work got more important than figuring out what was blowing up.  Downgrade for me is working fine now.  I gave MS SQL dumps so hopefully they can get a new build in the coming weeks.  If you are curious I am on version 13.0.15600.2 and stable thus far as I downgraded two days ago.</p>