Short Question on Performance

C

Christian Döring

Hi,

Is it ok to create a new instance of a class on every Page_Load?

Given the following code behind a form:

protected void Page_Load(object sender, EventArgs e)
{
myclass= new MyClass(myControl);
}

protected void btnStart_Click(object sender, EventArgs e)
{
myclass.loadXYZ(0);
}

And the snippet from MyClass

public MyClass (MyControl c)
{
this.mycontrol = c;
}
public loadXYZ(int x)
{
...
c.text="abc"
}

So I need a reference to myControl which is on the form. My first approach
was to just pass it by the constructor of MyClass on the Page_Load event. Is
this just fine or do I loose performance?
 
K

Karl Seguin [MVP]

It should be ok.

Object creation is only heavy if you are dong heavy stuff in the
contstructor...which you don't seem to be doing...ur just assigning a
reference..

Karl
 
K

Kevin Spencer

I might also mention that *every* object in the Page is re-created with each
Page_Load, including the Page class itself.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.

"Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
net> wrote in message news:[email protected]...
 
C

Christian Döring

Kevin Spencer said:
I might also mention that *every* object in the Page is re-created with
each Page_Load, including the Page class itself.
Okay, nice to know, that I do nothing unusual here. ;-)
"Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
net> wrote in message news:[email protected]...
No heavy stuff in there...

Thank you both for your help!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top