0

To make a general idea: I am trying to develop an application which, in the state I've brought it to, uses a dozen of globally declared List(s) and List(s)>, where the "T"'s are generally Textboxes, and a Class.

The Lists and Lists(of)Lists are used to store data manually introduced by the user in a graphical interface, while the Class is used for storing data related to an object, data which is also manually introduced into some TextBoxes.

The user can also Add/Remove both those Controls (Stackpanels / Wrappanels containing one or more groups of TextBlock-TextBox) and those Objects (Class type) . The whole data will then be written in an XML file.

Issue: I am trying to figure out how to free/release the memory which is allocated for the Controls/Objects after these are removed graphically and from the List(s), because I discovered that the no. of Kbs only increases during the execution of my app.

My questions:

  1. Do I have to worry about memory being allocated for the Controls/Objects and not being released?
  2. If the answer to (1.) is YES, then how can I release the allocated memory?
  3. Is "Class" the right way to define the structure of an object or should I use the "Struct" for this matter?

EDIT:

I have to mention that when the application starts, a "Menu" window is opened, which gives the user the possibility to create one or more New "User interface" windows (in which data is actually introduced) / to Open one or more previously created "User interface" windows (with data now read from an XML) -> which also lead to a substantial increase in memory usage.

NOTE: Memory used when:

  • the first window appears: ~ 12.000 K
  • one New window is created: ~ 19.000 K
  • you add Controls/Objects: going up
  • Why do you you even have globally declared lists of textboxes? (I'd imagine your only interested in their text) Oh and you'll probably find that the user isn't actually removing the controls, just hiding them.. Does your list size constantly increase – Sayse Aug 28 '13 at 07:50
  • I am using lists of textboxes because those objects can have different numbers of components (say one has 3 strings, one has 4 strings and so on) and, as I have an inside menu from which I can switch between these objects, I must (in my way of doing things) remove all and then add the number of textboxes that I need in that tabcontrol (which acts like a container) – Gabriel Flueran Aug 28 '13 at 07:58
  • don't create texboxes yourself, but use databinding and datatemplates instead ! – Dargos Aug 28 '13 at 09:00
  • I would, but I don't know anything about the topics you mentioned. However, I will soon need to use DataBinding to check the validity of the data introduced into the textboxes and I would mostly appreciate some starting points for it (links and so on). – Gabriel Flueran Aug 28 '13 at 09:07
  • I don't know how your "adding/removing" the control from your interface, but I'd imagine your problem is linked to the fact that `Control.Remove` doesn't dispose of the control, it is kind of a flakey implementation, I'm pretty sure Control is a child class of Window and needs to be disposed similarly, make sure you are calling `Control.Dispose`.. I learned all I know about databinding from MSDN, be wary that this is also [flakey in winforms](http://stackoverflow.com/questions/16980942/update-databinding-on-lost-focus-winforms) – Sayse Aug 28 '13 at 09:31
  • I visually add/remove the controls using stackpanel/wrappanel.children.remove(at/all) and also remove them from the lists. I happen to be a beginner in c# and started implementing this application just with a few reading and some "backup" from C – Gabriel Flueran Aug 28 '13 at 10:53

0 Answers0