title: How do you force SQL Server to release memory?
body: <blockquote>
    <p>What's a good way of checking how much (actual) memory is currently
    being used vs. how much is SQL Server allocated to itself?</p>
  </blockquote>
  
  <p>I've been resorting to <strong>memory_utilization_‌​percentage</strong> but that doesn't seem to change after running the following to release memory.</p>
  
  <pre><code>SELECT  [Memory_usedby_Sqlserver_MB] = ( physical_memory_in_use_kb / 1024 ) ,
          [Memory_utilization_percentage] = memory_utilization_percentage 
  FROM    sys.dm_os_process_memory;
  
  DBCC FREESYSTEMCACHE ('ALL')
  DBCC FREESESSIONCACHE
  DBCC FREEPROCCACHE
  
  SELECT  [Memory_usedby_Sqlserver_MB] = ( physical_memory_in_use_kb / 1024 ) ,
          [Memory_utilization_percentage] = memory_utilization_percentage 
  FROM    sys.dm_os_process_memory;
  </code></pre>
  
  <p>A solution is to drop <strong>max server memory</strong> for the SQL Server and increase it again to force SQL Server to release unused but allocated memory. However an issue with this approach is that we cannot be sure how far to reduce <strong>max server memory</strong>, hence run the risk of killing SQL Server. This is why it's important to understand how much SQL Server is 'actually' using before reducing the value for <strong>max server memory</strong>.</p>