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:
Public Function Paint_text(ByVal txt As String) As Bitmap Dim bm_source As New Bitmap(Image.FromFile("C:\piv.bmp")) Dim bm_dest As New Bitmap(CInt(bm_source.Width), CInt(bm_source.Height) Dim gr_dest As Graphics = Graphics.FromImage(bm_dest) gr_dest.DrawImage(bm_source, 0, 0, bm_dest.Width, bm_dest.Height) Dim mybrush As New Drawing2D.LinearGradientBrush(ClientRectangle, FontDialog1.Color, FontDialog1.Color, Drawing2D.LinearGradientMode.Horizontal) Dim myFont As New Font("Verdana", 12, FontStyle.Regula) gr_dest.DrawString(txt, myFont, mybrush, New RectangleF(x1 , y1 , x2 - x1, y2 - y1) Paint_text = bm_dest gr_dest.Dispose() mybrush.Dispose() mypen.Dispose() myFont.Dispose() bm_source.Dispose() bm_source = Nothing bm_dest = Nothing 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.




Reply With Quote