rekam Posted November 26, 2003 Posted November 26, 2003 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 ! Quote
Administrators PlausiblyDamp Posted November 26, 2003 Administrators Posted November 26, 2003 (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 June 22, 2005 by PlausiblyDamp Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
rekam Posted November 26, 2003 Author Posted November 26, 2003 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... Quote
Administrators PlausiblyDamp Posted November 26, 2003 Administrators Posted November 26, 2003 Could you post the code you are using to create the form elements and also how you are freeing them up. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
rekam Posted November 27, 2003 Author Posted November 27, 2003 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 :'( Quote
Administrators PlausiblyDamp Posted November 27, 2003 Administrators Posted November 27, 2003 (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 June 22, 2005 by PlausiblyDamp Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
rekam Posted November 27, 2003 Author Posted November 27, 2003 I check that. For now, It returns me an error "is not an instance of an object". So I'm searching Quote
rekam Posted November 28, 2003 Author Posted November 28, 2003 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 ! Quote
rekam Posted November 28, 2003 Author Posted November 28, 2003 One more question ! Is this syntax ... xmlFile = nothing 'xmlFile is an xmlDocument object declared before ...useful to something. Is that "memory free" ? Quote
Administrators PlausiblyDamp Posted November 28, 2003 Administrators Posted November 28, 2003 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. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.