Data Danger
Freshman
- Joined
- Mar 25, 2004
- Messages
- 29
I'm trying to track down a memory leak/Unreleased object that seems to happen when I use a particular way of opening a form. I have not included all dispose references but they are there in my code.
I have created a small test program that has 3 forms. Form1 just opens Form2 and Form2 will open up my report viewer and display my report.
Form2 is opened this way in button_click
Form2 has a button to open up my viewer
If I use
Form2 -
Form4 has the ShowReport method
Then the memory of Form4 is not release correctly
----------------
Now if I use
When I use the code above the Memory does get released correctly. Could somebody explain why this is? Also is it aways better to open an instance to another form by using the Sub New method.
-Paul
I have created a small test program that has 3 forms. Form1 just opens Form2 and Form2 will open up my report viewer and display my report.
Form2 is opened this way in button_click
Visual Basic:
Dim f2 As Form = New Form2
f2.ShowDialog()
f2.Dispose()
If I use
Form2 -
Visual Basic:
Private Sub btnViewReport1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnViewReport1.Click
Form4.ShowReport(New ddSummaryReport)
Form4.ShowDialog()
Form4.Dispose()
End Sub
Then the memory of Form4 is not release correctly
----------------
Now if I use
Visual Basic:
Private Sub btnViewReport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnViewReport.Click
Me.ShowReport(New ddSummaryReport())
End Sub
Private Sub ShowReport(ByVal rpt As ActiveReport)
Try
Me.connectString = "Provider=Microsoft.Jet.OLEDB.4.0;Jet"
rpt.DataSource = "SELECT What I Want"
Dim _ds As OleDBDataSource = CType(rpt.DataSource, OleDBDataSource)
' Create a new instance of the viewer form, pass document and parent form:
Dim _viewerForm As New Form3(rpt)
_viewerForm.Show()
Catch ex As ReportException
MessageBox.Show(ex.ToString())
End Try
End Sub
Public Class Form3
Public Sub New(ByVal rpt As ActiveReport)
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
Me.Text = rpt.Document.Name
viewerReport = rpt
rpt.Run(True)
arvMain.Document = rpt.Document
End Sub
End Class
-Paul
Last edited by a moderator: