c# - Destroy objects per instance -


I have many more complex answers for a simple question, so I ask about this question because of my situation I can not know what to do on the basis of those other answers enough . Garbage collection looks like a danger zone, so I will make a mistake in favor of caution.

I have a measuring object in which there is a quantity object and a weight object depends on the manufacturer, I would like to destroy the opposite object, that is, if a user adds a larger measurement, then I would like to eliminate the weight element of that example, because at that point there is only bloat. What should be done?

was edited for clarification:

  public class roenggyant {public string name {get; Set; } Public measurement measurement; Public Raw Industry (String En, Double D, Measurement Volume Unit Unit) {name = n; Measurement Volume.amount = (decimal) D; Measurement.volume.unit = Unit; // I want to get rid of the weight item on this example of measurement} Public roinggentant (string n, double D, measurement.Weight unit unit) {name = n; Measurement Weight.amount = (Decimal) D; Measurement Weight.unit = unit; // I to get rid of the section object on this example of measurement}}  

measurement

quantity and weight are simple squares with two fields.

If you are in the measurement constructor, then just type of non-essential type Do not build; This will remain as the default value of zero (as long as the volume and weight are not references and strokes), and any attempt of the wrong type will leave an exception .

Until the measurement object scope, the garbage collector could not collect the non-essential type, because it would be within the scope of measurement example, and at any time can be made principally, even in spite of your actual intentions.


Comments

Popular posts from this blog

Member with no value in F# -

java - Joda Time Interval Not returning what I expect -

c# - Showing a SelectedItem's Property -