Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hello !

 

I'm 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 !

  • Administrators
Posted (edited)

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 won't free up as often as on a PC with limited memory.

Edited by PlausiblyDamp

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

Okay, here's my code. I use this to display values for a parameter. There'are 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 parameter's key we want to display.

 

First of all, I delete all elements allready in the gbData, if there'are some.

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

ReDim tableauBox(Me.valuesParamDefault(key).length - 1)

 

And then I create the new tableauBox with the new elements

       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 :'(

  • Administrators
Posted (edited)

you could try disposing the controls instead of removing them.

 

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 can't test it just yet...

Edited by PlausiblyDamp

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

Yeah, it seems to work !! Thanks PlausiblyDamp !

 

But it's strange, I don't remember where, but I think I've read something about Dispose and Controls.Remove. It said that the Remove function worked the same as Dispose.

 

In the facts, Remove doesn't dispose anything...but Dispose remove the object from the Form. That's all I wanted. Thank you very much !

Posted

One more question !

 

Is this syntax ...

xmlFile = nothing 'xmlFile is an xmlDocument object declared before

...useful to something. Is that "memory free" ?

  • Administrators
Posted

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 won't free the resources then - that still relies on the garbage collector kicking in and freeing them up.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...