Hey, I have made app, which repaints and changes wallpaper after some period. But something goes wrong. Every time then function is called ~7 MB of memory are "ate". How to free it after doing job? I tried dispose, but nothing.


VB Code:
  1. Public Function Paint_text(ByVal txt As String) As Bitmap
  2.  
  3. Dim bm_source As New Bitmap(Image.FromFile("C:\piv.bmp"))
  4. Dim bm_dest As New Bitmap(CInt(bm_source.Width), CInt(bm_source.Height)
  5. Dim gr_dest As Graphics = Graphics.FromImage(bm_dest)
  6. gr_dest.DrawImage(bm_source, 0, 0, bm_dest.Width, bm_dest.Height)
  7.  
  8. Dim mybrush As New Drawing2D.LinearGradientBrush(ClientRectangle, FontDialog1.Color, FontDialog1.Color, Drawing2D.LinearGradientMode.Horizontal)
  9.  Dim myFont As New Font("Verdana",  12, FontStyle.Regula)
  10. gr_dest.DrawString(txt, myFont, mybrush, New RectangleF(x1 , y1 , x2 - x1, y2 - y1)
  11. Paint_text = bm_dest
  12.  
  13.         gr_dest.Dispose()
  14.         mybrush.Dispose()
  15.         mypen.Dispose()
  16.         myFont.Dispose()
  17.         bm_source.Dispose()
  18.         bm_source = Nothing
  19.         bm_dest = Nothing
  20.  
  21.     End Function

Then I set returned image to picturebox (~3MB). But it's OK. This is not why after every function call memory isn't cleared.