In VB.NET, I open a form in my application where I will place some charts using XTRACHARTS library.
Then, the memory gets is increased a lot, and when I close the form, the memory is never released any more.
Following, the sub that I close the form.
Private Sub XtraCharts_Close(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormC
losedEvent
Args) Handles MyBase.FormClosed
Me.PanChart.Controls.Remov
e(AreaChar
t) ' AreaChart is the chart object defined as private
Me.AreaChart = Nothing
' I believe that the following is not necessary, but I put it, in order to see what happen...!!
While Me.Controls.Count > 0
For Each ControlObj As Windows.Forms.Control In Me.Controls
Me.Controls.Remove(Control
Obj)
ControlObj = Nothing
Next
End While
Me.Close()
End Sub
Following, the code executed in the main form, that calls the "XtraCharts" form, and where I am trying to release the resources used by the charts objects (inside the "XtraCharts" form)
XtraCharts.ShowDialog()
XtraCharts = Nothing
XtraCharts.Dispose()
GC.Collect()
GC.WaitForPendingFinalizer
s()
By the way, if I try the following:
While Not XtraCharts.IsDisposed
XtraCharts = Nothing
XtraCharts.Dispose()
GC.Collect()
GC.WaitForPendingFinalizer
s()
End While
The loop never ends. In other words, XtraCharts.IsDisposed is allways false.....!!!
I am so confused about how to use the GC.
I need an example of the correct way to guarantee to release the unused memory...!!!
Thanks in advance,
Start Free Trial