I'm getting a collection of processes, adding them to a ListView, and deleting them from it when needed. All of this is done in a timer.

The problem, is that after a while, the app freezes. I think this is because I'm not disposing any variables.

Here's my code:

VB.NET Code:
  1. Private _processes As New List(Of String)()
  2.  
  3.         Dim killedProcs As New List(Of String)(_processes)
  4.         Dim processes As Process() = System.Diagnostics.Process.GetProcesses()
  5.         For Each proc As Process In processes
  6.  
  7.             Dim procId As String = proc.Id.ToString()
  8.             If Not _processes.Contains(procId) Then
  9.                 _processes.Add(procId)
  10.                 Dim lvi As New ListViewItem(proc.ProcessName)
  11.                 If strImageKey <> String.Empty Then
  12.                     lvi.ImageKey = strImageKey
  13.                 End If
  14.  
  15.                 lvi.Name = procId
  16.                 Try
  17.                     'Add Process ID to lvwProcess
  18.                     lvi.SubItems.Add(proc.Id.ToString())
  19.                 Catch ex As Exception
  20.  
  21.                 End Try
  22.                 Try
  23.                     'Add CPU usage to lvwProcess
  24.                     lvi.SubItems.Add("")
  25.                 Catch ex As Exception
  26.  
  27.                 End Try
  28.                 Try
  29.                     'Add memory usage to lvwProcess
  30.                     lvi.SubItems.Add(proc.WorkingSet64 / 1024 & " K")
  31.                 Catch ex As Exception
  32.  
  33.                 End Try
  34.                 Try
  35.                     'Add the companies name to the lvwProcess, also known as the Vendor Name
  36.                     lvi.SubItems.Add(proc.MainModule.FileVersionInfo.CompanyName)
  37.                 Catch ex As Exception
  38.  
  39.                 End Try
  40.                 Try
  41.                     lvi.SubItems.Add(proc.MainModule.FileVersionInfo.FileDescription)
  42.                 Catch ex As Exception
  43.  
  44.                 End Try
  45.                 Try
  46.                     'Adds the image path to the lvwProcess
  47.                     lvi.SubItems.Add(proc.MainModule.FileName)
  48.                 Catch ex As Exception
  49.  
  50.                 End Try
  51.  
  52.                 lvwProcess.Items.Add(lvi)
  53.  
  54.             Else
  55.                 killedProcs.Remove(procId)
  56.             End If
  57.  
  58.         Next
  59.  
  60.         'remove the killed procs in the list view
  61.         For Each procId As String In killedProcs
  62.             lvwProcess.Items.RemoveByKey(procId)
  63.         Next

I tried disposing of my process list, but the IDE wouldn't let me. That's the only thing I thought would need disposing since it is what hold all of the processes.

Any ideas?

Thanks