473,554 Members | 2,902 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Should I explicitly destroy objects

Hello:

I just wrote my first ASP.Net application. It worked fine on my machine and
when I put into production, the ASP.Net process reaches 50% quite fast and
then the system does not work anymore until I kill that process.

Obviously, this is not acceptable.

Looking back, I do not destroy any objects in my form. Would that be the
reasn why the application breaks down?

I could explicitly set objects to nothing in
I would like to know
Nov 19 '05 #1
8 1941
No you don't need to explicitly destroy managed objects. However, unmanaged
objects need to be released such as database connections, file handles etc
since the managed wrapper for these wrap around unmanaged objects, .NET does
not know how to free these objects.

I'd venture a guess that memory is not the cause of your application falling
over dead, you likely have some other nasty issue.

--
Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ www.lulu.com/owc
Forth-coming VSTO.NET - Wrox/Wiley 2006
-------------------------------------------------------

"vvenk" <vv***@discussi ons.microsoft.c om> wrote in message
news:47******** *************** ***********@mic rosoft.com...
Hello:

I just wrote my first ASP.Net application. It worked fine on my machine and when I put into production, the ASP.Net process reaches 50% quite fast and
then the system does not work anymore until I kill that process.

Obviously, this is not acceptable.

Looking back, I do not destroy any objects in my form. Would that be the
reasn why the application breaks down?

I could explicitly set objects to nothing in
I would like to know

Nov 19 '05 #2
As you said, this is not acceptable.
First place to look at I would say is to ensure that you close a connection
to the database when you are done with it. I also call Dispose on it after
Close for extra luck.

"vvenk" <vv***@discussi ons.microsoft.c om> wrote in message
news:47******** *************** ***********@mic rosoft.com...
Hello:

I just wrote my first ASP.Net application. It worked fine on my machine
and
when I put into production, the ASP.Net process reaches 50% quite fast and
then the system does not work anymore until I kill that process.

Obviously, this is not acceptable.

Looking back, I do not destroy any objects in my form. Would that be the
reasn why the application breaks down?

I could explicitly set objects to nothing in
I would like to know

Nov 19 '05 #3
Chris:

I tried destroying these objects in the page_unload event but that event is
triggered right after the page_load event!

Which event is the appropriate one for destroying these objects?

"Chris Botha" wrote:
As you said, this is not acceptable.
First place to look at I would say is to ensure that you close a connection
to the database when you are done with it. I also call Dispose on it after
Close for extra luck.

"vvenk" <vv***@discussi ons.microsoft.c om> wrote in message
news:47******** *************** ***********@mic rosoft.com...
Hello:

I just wrote my first ASP.Net application. It worked fine on my machine
and
when I put into production, the ASP.Net process reaches 50% quite fast and
then the system does not work anymore until I kill that process.

Obviously, this is not acceptable.

Looking back, I do not destroy any objects in my form. Would that be the
reasn why the application breaks down?

I could explicitly set objects to nothing in
I would like to know


Nov 19 '05 #4
My guess would be that you see the page_unload event so fast because your
computer is snappy. The page_unload event is a good place to destroy them,
if you mean conn.Close() and conn.Dispose(), because just setting them to
nothing won't help as in the old VB days.
"vvenk" <vv***@discussi ons.microsoft.c om> wrote in message
news:22******** *************** ***********@mic rosoft.com...
Chris:

I tried destroying these objects in the page_unload event but that event
is
triggered right after the page_load event!

Which event is the appropriate one for destroying these objects?

"Chris Botha" wrote:
As you said, this is not acceptable.
First place to look at I would say is to ensure that you close a
connection
to the database when you are done with it. I also call Dispose on it
after
Close for extra luck.

"vvenk" <vv***@discussi ons.microsoft.c om> wrote in message
news:47******** *************** ***********@mic rosoft.com...
> Hello:
>
> I just wrote my first ASP.Net application. It worked fine on my machine
> and
> when I put into production, the ASP.Net process reaches 50% quite fast
> and
> then the system does not work anymore until I kill that process.
>
> Obviously, this is not acceptable.
>
> Looking back, I do not destroy any objects in my form. Would that be
> the
> reasn why the application breaks down?
>
> I could explicitly set objects to nothing in
>
>
> I would like to know


Nov 19 '05 #5
You cannot destroy .Net objects. They are destroyed when Garbage Collection
destroys them.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Complex things are made up of
Lots of simple things.

"vvenk" <vv***@discussi ons.microsoft.c om> wrote in message
news:22******** *************** ***********@mic rosoft.com...
Chris:

I tried destroying these objects in the page_unload event but that event
is
triggered right after the page_load event!

Which event is the appropriate one for destroying these objects?

"Chris Botha" wrote:
As you said, this is not acceptable.
First place to look at I would say is to ensure that you close a
connection
to the database when you are done with it. I also call Dispose on it
after
Close for extra luck.

"vvenk" <vv***@discussi ons.microsoft.c om> wrote in message
news:47******** *************** ***********@mic rosoft.com...
> Hello:
>
> I just wrote my first ASP.Net application. It worked fine on my machine
> and
> when I put into production, the ASP.Net process reaches 50% quite fast
> and
> then the system does not work anymore until I kill that process.
>
> Obviously, this is not acceptable.
>
> Looking back, I do not destroy any objects in my form. Would that be
> the
> reasn why the application breaks down?
>
> I could explicitly set objects to nothing in
>
>
> I would like to know


Nov 19 '05 #6
Kevin:

Initially I was not destroying exactly for that reason. But when the Asp.Net
process was taking 50% of the memory with two users using the applictaion, I
thought I should explicitly destroy these objects.

Are you implying that the changes I have made will have no impact on the
memory problem?

"Kevin Spencer" wrote:
You cannot destroy .Net objects. They are destroyed when Garbage Collection
destroys them.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Complex things are made up of
Lots of simple things.

"vvenk" <vv***@discussi ons.microsoft.c om> wrote in message
news:22******** *************** ***********@mic rosoft.com...
Chris:

I tried destroying these objects in the page_unload event but that event
is
triggered right after the page_load event!

Which event is the appropriate one for destroying these objects?

"Chris Botha" wrote:
As you said, this is not acceptable.
First place to look at I would say is to ensure that you close a
connection
to the database when you are done with it. I also call Dispose on it
after
Close for extra luck.

"vvenk" <vv***@discussi ons.microsoft.c om> wrote in message
news:47******** *************** ***********@mic rosoft.com...
> Hello:
>
> I just wrote my first ASP.Net application. It worked fine on my machine
> and
> when I put into production, the ASP.Net process reaches 50% quite fast
> and
> then the system does not work anymore until I kill that process.
>
> Obviously, this is not acceptable.
>
> Looking back, I do not destroy any objects in my form. Would that be
> the
> reasn why the application breaks down?
>
> I could explicitly set objects to nothing in
>
>
> I would like to know


Nov 19 '05 #7
> Initially I was not destroying exactly for that reason. But when the
Asp.Net
process was taking 50% of the memory with two users using the applictaion,
I
thought I should explicitly destroy these objects.
An assumption on your part. First, 50% is not an amount, but a ratio, so I
have no idea how much memory you're talking about. Second, assuming that the
app *is* consuming an excessive amount of memory (and that is quite the
assumption; .Net manages memory quite well, but will not discard it
immediately), the real problem would be to determine exactly what is causing
the excessive use of memory. Let's say that your car is using too much gas.
Would you assume that changing the spark plugs would fix the problem, or
would you identify all of the possible causes of excessive gas use, and
check each related component to find out which one was misbehaving and why,
and then fix that component? In other words, some diagnostics are necessary
before any attempt to fix the issue is made.
Are you implying that the changes I have made will have no impact on the
memory problem?
If I implied that, I would be making an assumption myself. First, I have no
idea what changes you have made. You have talked about "destroying objects,"
but as I told you, that is not something you can do. They are managed, and
the option to destroy them is not one available to the developer. So, since
you say that "I tried destroying these objects in the page_unload event,"
and it is not possible to destroy .Net objects, I can't presume to know what
you did to your code as an attempt to destroy them.

I could presuppose that you assigned a null (Nothing) value to them, but if
so, that would be of no effect. For one thing, a variable or field is simply
a container for an object. It is not an object itself. When you set the
value of a variable, you are only saying to the computer, "when I reference
this name, I am referencing that object." When you set the value of a
variable to Nothing, you are saying to the computer, "when I reference this
name, I am not referencing anything."

So, in order to help you, you will need to fill in the blanks where I have
indicated. How much memory are we talking about? What sort of objects are
you using, and how are you using them?

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Complex things are made up of
Lots of simple things.

"vvenk" <vv***@discussi ons.microsoft.c om> wrote in message
news:A6******** *************** ***********@mic rosoft.com... Kevin:

Initially I was not destroying exactly for that reason. But when the
Asp.Net
process was taking 50% of the memory with two users using the applictaion,
I
thought I should explicitly destroy these objects.

Are you implying that the changes I have made will have no impact on the
memory problem?

"Kevin Spencer" wrote:
You cannot destroy .Net objects. They are destroyed when Garbage
Collection
destroys them.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Complex things are made up of
Lots of simple things.

"vvenk" <vv***@discussi ons.microsoft.c om> wrote in message
news:22******** *************** ***********@mic rosoft.com...
> Chris:
>
> I tried destroying these objects in the page_unload event but that
> event
> is
> triggered right after the page_load event!
>
> Which event is the appropriate one for destroying these objects?
>
> "Chris Botha" wrote:
>
>> As you said, this is not acceptable.
>> First place to look at I would say is to ensure that you close a
>> connection
>> to the database when you are done with it. I also call Dispose on it
>> after
>> Close for extra luck.
>>
>> "vvenk" <vv***@discussi ons.microsoft.c om> wrote in message
>> news:47******** *************** ***********@mic rosoft.com...
>> > Hello:
>> >
>> > I just wrote my first ASP.Net application. It worked fine on my
>> > machine
>> > and
>> > when I put into production, the ASP.Net process reaches 50% quite
>> > fast
>> > and
>> > then the system does not work anymore until I kill that process.
>> >
>> > Obviously, this is not acceptable.
>> >
>> > Looking back, I do not destroy any objects in my form. Would that be
>> > the
>> > reasn why the application breaks down?
>> >
>> > I could explicitly set objects to nothing in
>> >
>> >
>> > I would like to know
>>
>>
>>


Nov 19 '05 #8
If you are using database connections you have to close them and as I said I
also Dispose the connection after Close, don't know how important the
Dispose is. If you don't, then the connection pool will grow.
Just setting objects to nothing won't help.

"vvenk" <vv***@discussi ons.microsoft.c om> wrote in message
news:A6******** *************** ***********@mic rosoft.com...
Kevin:

Initially I was not destroying exactly for that reason. But when the
Asp.Net
process was taking 50% of the memory with two users using the applictaion,
I
thought I should explicitly destroy these objects.

Are you implying that the changes I have made will have no impact on the
memory problem?

"Kevin Spencer" wrote:
You cannot destroy .Net objects. They are destroyed when Garbage
Collection
destroys them.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Complex things are made up of
Lots of simple things.

"vvenk" <vv***@discussi ons.microsoft.c om> wrote in message
news:22******** *************** ***********@mic rosoft.com...
> Chris:
>
> I tried destroying these objects in the page_unload event but that
> event
> is
> triggered right after the page_load event!
>
> Which event is the appropriate one for destroying these objects?
>
> "Chris Botha" wrote:
>
>> As you said, this is not acceptable.
>> First place to look at I would say is to ensure that you close a
>> connection
>> to the database when you are done with it. I also call Dispose on it
>> after
>> Close for extra luck.
>>
>> "vvenk" <vv***@discussi ons.microsoft.c om> wrote in message
>> news:47******** *************** ***********@mic rosoft.com...
>> > Hello:
>> >
>> > I just wrote my first ASP.Net application. It worked fine on my
>> > machine
>> > and
>> > when I put into production, the ASP.Net process reaches 50% quite
>> > fast
>> > and
>> > then the system does not work anymore until I kill that process.
>> >
>> > Obviously, this is not acceptable.
>> >
>> > Looking back, I do not destroy any objects in my form. Would that be
>> > the
>> > reasn why the application breaks down?
>> >
>> > I could explicitly set objects to nothing in
>> >
>> >
>> > I would like to know
>>
>>
>>


Nov 19 '05 #9

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

Similar topics

1
15261
by: Thomas Ilsche | last post by:
Hi, how do I "explicitly destroy" an Object in PHP5 to make sure the destructor is called an the object destroyed? unset is not an option because there are multiple variables containing the object handle. Waiting for the end of the script is aswell a bad option because the order in which the destructores are called does matter.
303
17477
by: mike420 | last post by:
In the context of LATEX, some Pythonista asked what the big successes of Lisp were. I think there were at least three *big* successes. a. orbitz.com web site uses Lisp for algorithms, etc. b. Yahoo store was originally written in Lisp. c. Emacs The issues with these will probably come up, so I might as well mention them myself (which...
1
2263
by: Minkyu Kim | last post by:
Hi. Please check this simple test code. --------------------- class TestA: def __init__(self): print "init TestA" def __del__(self): print "del TestA" def SetEvent(self, event):
8
1115
by: Chris Mayers | last post by:
I am trying to track a suspected memory leak in an application I'm writing and through repeated simplification of my project, I have found the following which is quite easily replicated should you be prepared to give me 5 minutes of your time... Create a new C# (Probably the same in VB dotNET but I've not tried it) Windows application with...
4
4721
by: Steven T. Hatton | last post by:
I mistakenly set this to the comp.std.c++ a few days back. I don't believe it passed the moderator's veto - and I did not expect or desire anything different. But the question remains: ISO/IEC 14882:2003(E) §8.5 says:   To zero-initialize an object of type T means: 5...
7
6306
by: Claire | last post by:
How do I make sure Ive disposed of my objects please? Ive added interface IDispose to a base class. Ive several sub classes inheriting from this base class. I store one or other of these subclasses in a variable and call dispose(), but the Dispose() method of the base class is called rather than in the sub class example class baseclass...
4
1796
by: Peter Oliphant | last post by:
I'd like to be able to destroy a Timer in it's own event handler. That is, within it's tick handler I'd like to delete the Timer itself (e.g., for one-shot timers). Is this possible? In general, can a class instance destroy itself via one of it's own methods?
16
4531
by: LP | last post by:
Hello, I am trying to use .NET with Excel. I installed Office 2003 and selected ..NET programming suport option, so it installed all those PIA, as MS sugests. But I can not find a way to destroy Excel process, it still hangs in the taks manager' Processes as running. I am trying very simple code (see below), but Excel wont go away, I tried...
3
1542
by: Matt B | last post by:
Subject is probably poorly worded, but bear with me as I describe the situation that has me puzzled. I create "Save" objects from a Save "factory" class. Many different windows access this method to get their save object. I do this because I am interested from the save factory when any of the many windows uses that save object. I keep...
0
7581
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7506
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7872
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6123
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5423
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5142
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3545
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2006
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
823
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.