开发者

Form reference wasting memory?

My apologies but I am a complete novice. Hopefully a quick one for you guys, though I can't find the answer anywhere.

If I create a reference to a form in another form do I end up with two lots of the form in memory or two markers for the same form in memory.

I'd like to beable to reference controls on the other form to change the values etc. If there is a better way, some pointers would be nice but I don;t expect you to do the work form me.

I am using:

private Form1 _myForm1;

public Form1 MyForm1
{
   get{return _myForm1;}
   set{_myForm1 = value;}
}

Then in the Contructor:

public Form2()
{
   MyForm1 = (Form1)Form1.ActiveForm;
   InitializeComponent();
}

The开发者_如何转开发 thought came to me that I am most likely really wasting memory.

Many thanks


An additional reference to an existing object will only take up the space needed to store the reference. I.e. the object itself is not copied. However, the object will not be reclaimed by the garbage collector until it is no longer referenced.


You're wasting 4 or 8 bytes. The variable is just a pointer to the same object.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜