Copying data between two forms, allocated memory continues to grow

F

Federico Caselli

Hi,

I have a simple memory problem with two forms on a MDI project.

The first form (MainForm) open a second one (ImageForm).

Both the forms have an instance to a dataset (DataSet1).

On the ImageForm Form_Load event, I wrote code to copy all the records from
the MainForm.DataSet1.TB_Images dataTable to the ImageForm.DataSet1.TB_Images
dataTable. Note that TB_Images has an Image Field.

I can't understand why opening and closing ImageForm many times, the
allocated memory continues to grow.

This is the code:

' the MainForm opens the ImageForm:
Private Sub OpenImageForm()
Dim f As New ImageForm
If f.ShowDialog(Me.ParentForm) = Windows.Forms.DialogResult.OK Then
'do stuff (or do nothing, the problem doesn't change)
End If
f = Nothing
End Sub

'the Form_Load event of the ImageForm
Private Sub ImageForm_Load(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles MyBase.Load
Me.DataSet1.TB_Images.Clear()
For Each rwImages As DataSet1.TB_ImagesRow In _
CType(Me.Owner, MDIParent)._MainForm.DataSet1.TB_Images
Me.DataSet1.TB_Images.ImportRow(rwImages)
Next
End Sub

Any help appreciated!
 
R

Robbe Morris - [MVP] C#

You should be asking yourself

"Why did I do this?"

"Both the forms have an instance to a dataset (DataSet1)."

Why don't you have a separate class with a static instance
of this DataSet that both forms can access as needed?

--
Robbe Morris [Microsoft MVP - Visual C#]
AdvancedXL Server, Designer, and Data Analyzer
Convert cell ranges in Excel to rule driven web apps
without IT programmers.
Free download: http://www.equalssolved.com/default.aspx
 
F

Federico Caselli

Looks nice!

As you can see I'm not that expert :)

Could you please write some sample code?

Thanks!


Robbe Morris - [MVP] C# said:
You should be asking yourself

"Why did I do this?"

"Both the forms have an instance to a dataset (DataSet1)."

Why don't you have a separate class with a static instance
of this DataSet that both forms can access as needed?

--
Robbe Morris [Microsoft MVP - Visual C#]
AdvancedXL Server, Designer, and Data Analyzer
Convert cell ranges in Excel to rule driven web apps
without IT programmers.
Free download: http://www.equalssolved.com/default.aspx




Federico Caselli said:
Hi,

I have a simple memory problem with two forms on a MDI project.

The first form (MainForm) open a second one (ImageForm).

Both the forms have an instance to a dataset (DataSet1).

On the ImageForm Form_Load event, I wrote code to copy all the records
from
the MainForm.DataSet1.TB_Images dataTable to the
ImageForm.DataSet1.TB_Images
dataTable. Note that TB_Images has an Image Field.

I can't understand why opening and closing ImageForm many times, the
allocated memory continues to grow.

This is the code:

' the MainForm opens the ImageForm:
Private Sub OpenImageForm()
Dim f As New ImageForm
If f.ShowDialog(Me.ParentForm) = Windows.Forms.DialogResult.OK Then
'do stuff (or do nothing, the problem doesn't change)
End If
f = Nothing
End Sub

'the Form_Load event of the ImageForm
Private Sub ImageForm_Load(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles MyBase.Load
Me.DataSet1.TB_Images.Clear()
For Each rwImages As DataSet1.TB_ImagesRow In _
CType(Me.Owner, MDIParent)._MainForm.DataSet1.TB_Images
Me.DataSet1.TB_Images.ImportRow(rwImages)
Next
End Sub

Any help appreciated!
 
Top