jonwondering
Programmer
Hey everybody, I have a little problem and I can't figure it out. I got a memory leak... Let's say I have a txt file with the following values in there:
Red
Green
Blue
My program reads in those values every 10 seconds and stores them as a menu in a ContextMenu control. I have done that with a timer (obviously) and everytime before it loads the items in a menu, it clears the menu (so that the menuitems would not pile up).
Here's the code inside the loop:
The problem is that every time the loop executes, it creates new MenuItems and new Handlers for them, making the memory usage of the program increase...
Does anybody know how I can delete those MenuItems and their Handlers to free up that space?
(The problem is that they are created dynamically...)
Thanks,
Jon
Red
Green
Blue
My program reads in those values every 10 seconds and stores them as a menu in a ContextMenu control. I have done that with a timer (obviously) and everytime before it loads the items in a menu, it clears the menu (so that the menuitems would not pile up).
Here's the code inside the loop:
Code:
Dim Z As MenuItem
While ("... Not the end of file ...")
' Here 'Temp' stores the name of the color
Z = New MenuItem(Temp)
Me.ContextMenu1.MenuItems.Add(Z)
AddHandler Z.Click, AddressOf Implement_Click
End While
Private Sub Implement_Click(ByVal Sender As Object, ByVal e As EventArgs) Handles Z.Click
MsgBox("You clicked here")
End Sub
The problem is that every time the loop executes, it creates new MenuItems and new Handlers for them, making the memory usage of the program increase...
Does anybody know how I can delete those MenuItems and their Handlers to free up that space?
(The problem is that they are created dynamically...)
Thanks,
Jon