title: WPF Memory Usage
body: <h2>Application:</h2>
  
  <ul>
  <li>WPF Application consisting of a textbox on top and a listbox below</li>
  <li>Users type a string in the TextBox to find employees, and search results are displayed in the ListBox</li>
  <li>ListBox uses DataTemplates to display elements (shows employee name, department, phone and a thumbnail picture.) </li>
  </ul>
  
  <h2>Implementation:</h2>
  
  <ul>
  <li>At application startup I query the database and retrieve all employees and related information to be shown in the ListBox. This is kept in memory the entire time.</li>
  <li>After application startup, all the searchable data is in memory and searches are virtually instantaneous. All searches are performed on the data already in memory. </li>
  <li>Search results are displayed in the ListBox using DataTemplates. Thumbnail picture, name, phone, department, etc, are shown in each ListBox item.</li>
  </ul>
  
  <h2>Problem:</h2>
  
  <ul>
  <li>At startup the memory usage is about 200MB. </li>
  <li>As data is changed in the listbox, either via a new search or a simply scrolling down the listbox, memory consumption increases.</li>
  <li>When users scroll down the listbox slowly, memory increases faster. As you scroll it up and down memory quickly reaches 1GB.</li>
  </ul>
  
  <p>There are is no code creating controls manually - everything is done via data binding.</p>
  
  <p>Why am I seeing this behavior? What can I do to fix it? Please help!</p>
  
  <p>UPDATE:
  I figured out that the problem is not a memory leak. The issue here is that the listbox is creating objects to display the images of the employee and is not releasing for the garbage collector after the listboxitem gets out of the window. The CleanUpVirtualizedItem event occurs as I expected but the memory is still not released. Any ideas?</p>