ASP.NET Object Disposal

M

mukulprabhu

Hello there,

Is it compulsory that the component objects created in code behind
should be disposed explicitly.

For eg.

first.cs
index.aspx.cs
-----------------------------------------------------
-----------------------------------------------------
Class first first
objFirst = new first();
{
page_load()
method A () {some code} {
}
objFirst.A();
}

in the above example is it nessesary to dispose "objFirst" object.

Anticipating your reply.

Thanx in advance.
 
S

Sarat Pediredla

Mukul,

I never dispose my component objects explicitly. I wonder what gave you
the idea? I am assuming you are putting first.cs in App_Data (assuming
you are using .NET 2.0) but nevertheless the Garbage Collection should
handle this.

Sarat
 
G

Guest

Objects normailly do not need to be disposed unless they have resources or
referencess to other objects that have unmanaged resources that need to be
disposed (file handles, bitmaps, network streams, sockets, connections, etc.)

If your object has a Dispose method, you can call it, or have your class
implement the IDisposable pattern and it can call it.
Otherwise, objects are destroyed automatically by the runtime and in the
case of an ASP.NET page, everything goes away anyway as soon as the page
lifecycle is complete and the HTML has been sent out to the browser.

Peter
 

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,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top