free memory

rekam

Active member
Joined
Oct 7, 2003
Messages
43
Location
Switzerland
Hello !

Im actually creating windows.Form elements at runtime.
The thing is, when I change the selected item of a TreeView, all elements are killed and recreated (there are more or less of them depending of the selected item).

After a few minute changing the selected item, if I look to the memory process, it uses 100 Mb !! Gasp !

When I create elements, I put them in an array. The first line of the method which create them is Redim myArray(quantity).

It seems this is not enough to really delete them from the memory. So what should I do ? :confused:

Thanks !
 
How much memory do you have installed in that PC?
Under .Net memory is only released when the garbage collector decides you need some memory back - if you have lots of available RAM then it wont free up as often as on a PC with limited memory.
 
Last edited by a moderator:
I have 250Mb RAM. But if I go up and down my TreeView, after less than one minute, I have an error message outOfMemory exception...
 
Okay, heres my code. I use this to display values for a parameter. Thereare 20 parameters, which have each a certain number of values.
These values are displayed in TextBox. Each Textbox is saved in the array tableauBox. So tableauBox is an array of TextBox.
gbData is the GroupBox where TextBoxes are displayed.
ValuesParamDefault is an object I created which is an array which has a specified length depending of the parameters key we want to display.

First of all, I delete all elements allready in the gbData, if thereare some.
Code:
Dim cpt as integer
For cpt = 0 To Me.tableauBox.Length - 1
       Me.gbData.Controls.Remove(Me.tableauBox(cpt))
Next

Then I Redim the tableauBox
Code:
ReDim tableauBox(Me.valuesParamDefault(key).length - 1)

And then I create the new tableauBox with the new elements
Code:
        Dim i As Integer
        For i = 0 To Me.nbCases
            tableauBox(i) = New System.Windows.Forms.TextBox
            tableauBox(i).BackColor = couleurFond
            tableauBox(i).Location = New System.Drawing.Point(x, y)
            tableauBox(i).Size = New System.Drawing.Size(longueurChamp, largeurChamp)
            tableauBox(i).Text = cpt
            tableauBox(i).Tag = cpt
            tableauBox(i).Tag = posTrim
            tableauBox(i).MaxLength = 6
            tableauBox(i).Font = styles.pTexte()
            Its value
            tableauBox(i).Text = Me.valuesParamDefault(key).table(market, posValue)
            Me.gbData.Controls.Add(tableauBox(i))
        Next
    End Function

When I go up and down the TreeView, these funcions are called and the memory raise more and more :(
 
you could try disposing the controls instead of removing them.

Code:
Dim cpt As Integer
For cpt = 0 To Me.tableauBox.Length - 1
       Me.gbData.Controls(cpt).Dispose
Next

not near VS at the moment so I cant test it just yet...
 
Last edited by a moderator:
Yeah, it seems to work !! Thanks PlausiblyDamp !

But its strange, I dont remember where, but I think Ive read something about Dispose and Controls.Remove. It said that the Remove function worked the same as Dispose.

In the facts, Remove doesnt dispose anything...but Dispose remove the object from the Form. Thats all I wanted. Thank you very much !
 
One more question !

Is this syntax ...
Code:
xmlFile = nothing xmlFile is an xmlDocument object declared before
...useful to something. Is that "memory free" ?
 
setting something to nothing lets the garbage collector know the object is no longer needed there and then rather than when the variable goes out of scope.
However it wont free the resources then - that still relies on the garbage collector kicking in and freeing them up.
 
Back
Top