I'm working with C# and .NET Framework 4.0 and Windows Forms.
On my project I have three custom objects that inherits from MyControl
class (MyControl
class inherits from UserControl
).
I have this code:
private void ShowControlForBatchStatus(BatchStatus batchStatus)
{
MyControl control = null;
panelContainer.Controls.Clear();
if (batchStatus == BatchStatus.NoBatch)
{
control = new InicializeLevel();
}
else if ((batchStatus == BatchStatus.BatchRunning) ||
(batchStatus == BatchStatus.BatchPaused))
{
control = new Stadistics();
}
else if (batchStatus == BatchStatus.BatchFinish)
{
control = new FinishBatch();
}
panelContainer.Controls.Add(control);
}
Now I think that if it is correct to declare a MyControl control
variable when I'm going to use bigger control like FinishBatch
. I think that if compiler allocate memory for a MyControl
object, and now I use a bigger one for that variable, is that a problem?
Maybe, I'm confuse and the compiler only allocate memory when I do new FinishBatch();
.
Does the compiler allocate memory when I declare a variable?