S
sheng shan
there's a memory leak exist in such a simple app below:
the app only have a timer and a form
timer's interval is 100ms
below is the code in vb.net with cf sp1:
Public Class Form1
Inherits System.Windows.Forms.Form
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents Timer1 As System.Windows.Forms.Timer
Private xval As Byte
Private yval As Byte
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As
Boolean)
MyBase.Dispose(disposing)
End Sub
'NOTE: The following procedure is required by the Windows Form
Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
Private Sub InitializeComponent()
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.Timer1 = New System.Windows.Forms.Timer
Me.TextBox2 = New System.Windows.Forms.TextBox
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(344, 96)
Me.TextBox1.Size = New System.Drawing.Size(136, 21)
Me.TextBox1.Text = "TextBox1"
'
'Timer1
'
Me.Timer1.Enabled = True
'
'TextBox2
'
Me.TextBox2.Location = New System.Drawing.Point(192, 40)
Me.TextBox2.Size = New System.Drawing.Size(176, 21)
Me.TextBox2.Text = "TextBox2"
'
'Form1
'
Me.Controls.Add(Me.TextBox2)
Me.Controls.Add(Me.TextBox1)
Me.Text = "Form1"
End Sub
Public Shared Sub Main()
Application.Run(New Form1)
End Sub
#End Region
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
Dim CalcVal As Single
Dim TempVal As Single
Dim TempStr As Single
If xval < 255 Then
xval = xval + 1
yval = yval + 1
Else
xval = 0
yval = 0
End If
CalcVal = Convert.ToSingle(Convert.ToSingle(xval) +
Convert.ToSingle(yval) * 256)
TempVal = CalcVal / 65536 * 100
'TempStr = TempVal.ToString("0.0") & "kN"
TempStr = Int(TempVal * 10 + 0.5) / 10
TextBox1.Text = TempStr & "kN"
TextBox2.Text = Microsoft.VisualBasic.TimeOfDay
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
xval = 0
yval = 0
End Sub
End Class
run the app,then check the memory of ce system,you will find a memory
leak.
the app only have a timer and a form
timer's interval is 100ms
below is the code in vb.net with cf sp1:
Public Class Form1
Inherits System.Windows.Forms.Form
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents Timer1 As System.Windows.Forms.Timer
Private xval As Byte
Private yval As Byte
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As
Boolean)
MyBase.Dispose(disposing)
End Sub
'NOTE: The following procedure is required by the Windows Form
Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
Private Sub InitializeComponent()
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.Timer1 = New System.Windows.Forms.Timer
Me.TextBox2 = New System.Windows.Forms.TextBox
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(344, 96)
Me.TextBox1.Size = New System.Drawing.Size(136, 21)
Me.TextBox1.Text = "TextBox1"
'
'Timer1
'
Me.Timer1.Enabled = True
'
'TextBox2
'
Me.TextBox2.Location = New System.Drawing.Point(192, 40)
Me.TextBox2.Size = New System.Drawing.Size(176, 21)
Me.TextBox2.Text = "TextBox2"
'
'Form1
'
Me.Controls.Add(Me.TextBox2)
Me.Controls.Add(Me.TextBox1)
Me.Text = "Form1"
End Sub
Public Shared Sub Main()
Application.Run(New Form1)
End Sub
#End Region
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
Dim CalcVal As Single
Dim TempVal As Single
Dim TempStr As Single
If xval < 255 Then
xval = xval + 1
yval = yval + 1
Else
xval = 0
yval = 0
End If
CalcVal = Convert.ToSingle(Convert.ToSingle(xval) +
Convert.ToSingle(yval) * 256)
TempVal = CalcVal / 65536 * 100
'TempStr = TempVal.ToString("0.0") & "kN"
TempStr = Int(TempVal * 10 + 0.5) / 10
TextBox1.Text = TempStr & "kN"
TextBox2.Text = Microsoft.VisualBasic.TimeOfDay
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
xval = 0
yval = 0
End Sub
End Class
run the app,then check the memory of ce system,you will find a memory
leak.