473,473 Members | 2,167 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

ASP.NET Object Disposal

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.

Aug 20 '06 #1
2 4480
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

mu*********@gmail.com wrote:
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.
Aug 20 '06 #2
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
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"mu*********@gmail.com" wrote:
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.

Aug 21 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

34
by: yensao | last post by:
Hi, I have a hard time to understand difference and similarities between Relational database model and the Object-Oriented model. Can somebody help me with this? Thank you in advance. ...
16
by: Daniel Mori | last post by:
If an object implements the IDisposable interface (regardless if its a framework object or a user object), should I always dispose of that object out of principle?
29
by: web1110 | last post by:
If I have 2 variables, A and B, referencing the same object and then do a A.Dispose(), what happens to B?
5
by: theinvisibleGhost | last post by:
I'm having a problem that occurs at random in my app. I get an exception "Cannot Access a disposed object" In MSCorLib when calling boolean Change (int32, int32) Stack trace reveals...
3
by: Chris | last post by:
I am just wondering if I did this the best way possible. I needed to add a double boarder around a label box. So I made a pen in the class, and do the drawing of the rectangles in the onpaint...
16
by: anonymous.user0 | last post by:
The way I understand it, if I have an object Listener that has registered as a listener for some event Event that's produced by an object Emitter, as long as Emitter is still allocated Listener...
2
by: Steve | last post by:
I instantiate a form and within that form I instatiate an object from a class i created. When i close the form it is no longer referenced anywhere so my understanding is that the garbage...
20
by: Justin Rich | last post by:
so im trying to be good and not leave anything hanging open but i guess ive seen a variety of ways to kill objects.. is there like a recommended way? basically im looking for best practices for...
2
by: Neil Chambers | last post by:
All, I have a class describing various actions to take against a LINQ to SQL datasource. What are the pros/cons of instantiating the LINQ object either in the root of the class (for lack of a...
9
by: Duggi | last post by:
I used to wonder why MS implemented C# to accept the following code using (Font f = new Font()) { // some code here. } While the same can be achieved through {
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.