471,355 Members | 1,666 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,355 software developers and data experts.

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 1837
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***@discussions.microsoft.com> wrote in message
news:47**********************************@microsof t.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***@discussions.microsoft.com> wrote in message
news:47**********************************@microsof t.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***@discussions.microsoft.com> wrote in message
news:47**********************************@microsof t.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***@discussions.microsoft.com> wrote in message
news:22**********************************@microsof t.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***@discussions.microsoft.com> wrote in message
news:47**********************************@microsof t.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***@discussions.microsoft.com> wrote in message
news:22**********************************@microsof t.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***@discussions.microsoft.com> wrote in message
news:47**********************************@microsof t.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***@discussions.microsoft.com> wrote in message
news:22**********************************@microsof t.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***@discussions.microsoft.com> wrote in message
news:47**********************************@microsof t.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***@discussions.microsoft.com> wrote in message
news:A6**********************************@microsof t.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***@discussions.microsoft.com> wrote in message
news:22**********************************@microsof t.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***@discussions.microsoft.com> wrote in message
>> news:47**********************************@microsof t.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***@discussions.microsoft.com> wrote in message
news:A6**********************************@microsof t.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***@discussions.microsoft.com> wrote in message
news:22**********************************@microsof t.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***@discussions.microsoft.com> wrote in message
>> news:47**********************************@microsof t.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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Thomas Ilsche | last post: by
303 posts views Thread by mike420 | last post: by
8 posts views Thread by Chris Mayers | last post: by
4 posts views Thread by Steven T. Hatton | last post: by
7 posts views Thread by Claire | last post: by
4 posts views Thread by Peter Oliphant | last post: by
3 posts views Thread by Matt B | last post: by
reply views Thread by XIAOLAOHU | last post: by

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.