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!

You have asked the wrong question by Robbe

Robbe
Mon Feb 18 13:16:22 CST 2008

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" <FedericoCaselli@discussions.microsoft.com> wrote in
message news:956AB9A6-397C-41DB-B11A-84A3535EDEB0@microsoft.com...
> 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!
>
>
>
>


RE: You have asked the wrong question by FedericoCaselli

FedericoCaselli
Tue Feb 19 01:56:00 CST 2008

Looks nice!

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

Could you please write some sample code?

Thanks!


"Robbe Morris - [MVP] C#" wrote:

> 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" <FedericoCaselli@discussions.microsoft.com> wrote in
> message news:956AB9A6-397C-41DB-B11A-84A3535EDEB0@microsoft.com...
> > 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!
> >
> >
> >
> >
>
>

RE: You have asked the wrong question by FedericoCaselli

FedericoCaselli
Tue Feb 19 05:16:01 CST 2008

Done!

I've found an example here:

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2098238&SiteId=1

It works fine (what a discovery...)!

Thank you.