Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Memory leak on ASP.NET web site

Reply
Thread Tools

Memory leak on ASP.NET web site

 
 
Jon Davis
Guest
Posts: n/a
 
      06-04-2004
OK I have a web app that I built that makes MANY calls to the DB in each
request. The app wasn't tuned for scalability so this wasn't a problem, but
time is too short to redesign how the database is accessed because the data
that's being stored is time relevant and the web app will be thrown out in a
few months. Since I try to separate the OleDb stuff from the business logic,
I just create new database connections and trust that those connections will
be closed and expunged when the response ends.

But I'm finding that between SQL Server and IIS the machine is quickly
running out of RAM, even when the session (where I'm caching data in a
custom user object) terminates. After 20 or so page hits (containing several
database hits per page hit) the server loses like 600MB or RAM. I wouldn't
care since the access load is trivial, except that this RAM is NEVER
re-gained. Resetting SQL Server returns about 200MB and then resetting IIS
returns about 400MB. Again, this is long after the sessions have terminated.
And I host nothing in the Application collection.

Am I wrong in my understanding that database connections automatically close
and are destroyed when the containing object destroys itself (when the web
page's response ends)?

I have tried forcing all new database connections to be kept in an ArrayList
in Global and then go through the ArrayList and close and remove all of the
connections when Global's EndRequest method executes, but this doesn't seem
to do anything for me memory-wise.

What is going on?!

Jon


 
Reply With Quote
 
 
 
 
Jon Davis
Guest
Posts: n/a
 
      06-04-2004
> I have tried forcing all new database connections to be kept in an
ArrayList
> in Global and then go through the ArrayList and close and remove all of

the
> connections when Global's EndRequest method executes, but this doesn't

seem
> to do anything for me memory-wise.


... Oh and it doesn't do anything because the Session object isn't exposed in
this method.

Jon

"Jon Davis" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> OK I have a web app that I built that makes MANY calls to the DB in each
> request. The app wasn't tuned for scalability so this wasn't a problem,

but
> time is too short to redesign how the database is accessed because the

data
> that's being stored is time relevant and the web app will be thrown out in

a
> few months. Since I try to separate the OleDb stuff from the business

logic,
> I just create new database connections and trust that those connections

will
> be closed and expunged when the response ends.
>
> But I'm finding that between SQL Server and IIS the machine is quickly
> running out of RAM, even when the session (where I'm caching data in a
> custom user object) terminates. After 20 or so page hits (containing

several
> database hits per page hit) the server loses like 600MB or RAM. I wouldn't
> care since the access load is trivial, except that this RAM is NEVER
> re-gained. Resetting SQL Server returns about 200MB and then resetting IIS
> returns about 400MB. Again, this is long after the sessions have

terminated.
> And I host nothing in the Application collection.
>
> Am I wrong in my understanding that database connections automatically

close
> and are destroyed when the containing object destroys itself (when the web
> page's response ends)?
>
> I have tried forcing all new database connections to be kept in an

ArrayList
> in Global and then go through the ArrayList and close and remove all of

the
> connections when Global's EndRequest method executes, but this doesn't

seem
> to do anything for me memory-wise.
>
> What is going on?!
>
> Jon
>
>



 
Reply With Quote
 
 
 
 
Jon Davis
Guest
Posts: n/a
 
      06-04-2004
> I have tried forcing all new database connections to be kept in an
ArrayList
> in Global


Oh, and I meant to say I keep them in the Session object, with the intent to
close them (and then remove them from the ArrayList) when the page ends.

How can I do this? The Session object isn't exposed in the Request_End
method in Global.

Jon


"Jon Davis" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> OK I have a web app that I built that makes MANY calls to the DB in each
> request. The app wasn't tuned for scalability so this wasn't a problem,

but
> time is too short to redesign how the database is accessed because the

data
> that's being stored is time relevant and the web app will be thrown out in

a
> few months. Since I try to separate the OleDb stuff from the business

logic,
> I just create new database connections and trust that those connections

will
> be closed and expunged when the response ends.
>
> But I'm finding that between SQL Server and IIS the machine is quickly
> running out of RAM, even when the session (where I'm caching data in a
> custom user object) terminates. After 20 or so page hits (containing

several
> database hits per page hit) the server loses like 600MB or RAM. I wouldn't
> care since the access load is trivial, except that this RAM is NEVER
> re-gained. Resetting SQL Server returns about 200MB and then resetting IIS
> returns about 400MB. Again, this is long after the sessions have

terminated.
> And I host nothing in the Application collection.
>
> Am I wrong in my understanding that database connections automatically

close
> and are destroyed when the containing object destroys itself (when the web
> page's response ends)?
>
> I have tried forcing all new database connections to be kept in an

ArrayList
> in Global and then go through the ArrayList and close and remove all of

the
> connections when Global's EndRequest method executes, but this doesn't

seem
> to do anything for me memory-wise.
>
> What is going on?!
>
> Jon
>
>



 
Reply With Quote
 
Jon Davis
Guest
Posts: n/a
 
      06-04-2004

"Jon Davis" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> > I have tried forcing all new database connections to be kept in an

> ArrayList
> > in Global

>
> Oh, and I meant to say I keep them in the Session object, with the intent

to
> close them (and then remove them from the ArrayList) when the page ends.
>
> How can I do this? The Session object isn't exposed in the Request_End
> method in Global.


Nevermind, I already have all pages' code-behind inheret from a base class,
and I simply set up a deconstructor.

Will report here whether this (closing all open connections) clears the
memory leak.

Jon


> "Jon Davis" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > OK I have a web app that I built that makes MANY calls to the DB in each
> > request. The app wasn't tuned for scalability so this wasn't a problem,

> but
> > time is too short to redesign how the database is accessed because the

> data
> > that's being stored is time relevant and the web app will be thrown out

in
> a
> > few months. Since I try to separate the OleDb stuff from the business

> logic,
> > I just create new database connections and trust that those connections

> will
> > be closed and expunged when the response ends.
> >
> > But I'm finding that between SQL Server and IIS the machine is quickly
> > running out of RAM, even when the session (where I'm caching data in a
> > custom user object) terminates. After 20 or so page hits (containing

> several
> > database hits per page hit) the server loses like 600MB or RAM. I

wouldn't
> > care since the access load is trivial, except that this RAM is NEVER
> > re-gained. Resetting SQL Server returns about 200MB and then resetting

IIS
> > returns about 400MB. Again, this is long after the sessions have

> terminated.
> > And I host nothing in the Application collection.
> >
> > Am I wrong in my understanding that database connections automatically

> close
> > and are destroyed when the containing object destroys itself (when the

web
> > page's response ends)?
> >
> > I have tried forcing all new database connections to be kept in an

> ArrayList
> > in Global and then go through the ArrayList and close and remove all of

> the
> > connections when Global's EndRequest method executes, but this doesn't

> seem
> > to do anything for me memory-wise.
> >
> > What is going on?!
> >
> > Jon
> >
> >

>
>



 
Reply With Quote
 
Jon Davis
Guest
Posts: n/a
 
      06-04-2004
> Will report here whether this (closing all open connections) clears the
> memory leak.


No it does not. Anyone know what would cause such a drastic memory leak?
Again, lots of data is cached in the Session object, but even when the
Session has expired, no change is made to the memory and IIS and SQL Server
are taking up massive amounts of RAM.

Jon


"Jon Davis" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
> "Jon Davis" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > > I have tried forcing all new database connections to be kept in an

> > ArrayList
> > > in Global

> >
> > Oh, and I meant to say I keep them in the Session object, with the

intent
> to
> > close them (and then remove them from the ArrayList) when the page ends.
> >
> > How can I do this? The Session object isn't exposed in the Request_End
> > method in Global.

>
> Nevermind, I already have all pages' code-behind inheret from a base

class,
> and I simply set up a deconstructor.
>
> Will report here whether this (closing all open connections) clears the
> memory leak.
>
> Jon
>
>
> > "Jon Davis" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> > > OK I have a web app that I built that makes MANY calls to the DB in

each
> > > request. The app wasn't tuned for scalability so this wasn't a

problem,
> > but
> > > time is too short to redesign how the database is accessed because the

> > data
> > > that's being stored is time relevant and the web app will be thrown

out
> in
> > a
> > > few months. Since I try to separate the OleDb stuff from the business

> > logic,
> > > I just create new database connections and trust that those

connections
> > will
> > > be closed and expunged when the response ends.
> > >
> > > But I'm finding that between SQL Server and IIS the machine is quickly
> > > running out of RAM, even when the session (where I'm caching data in a
> > > custom user object) terminates. After 20 or so page hits (containing

> > several
> > > database hits per page hit) the server loses like 600MB or RAM. I

> wouldn't
> > > care since the access load is trivial, except that this RAM is NEVER
> > > re-gained. Resetting SQL Server returns about 200MB and then resetting

> IIS
> > > returns about 400MB. Again, this is long after the sessions have

> > terminated.
> > > And I host nothing in the Application collection.
> > >
> > > Am I wrong in my understanding that database connections automatically

> > close
> > > and are destroyed when the containing object destroys itself (when the

> web
> > > page's response ends)?
> > >
> > > I have tried forcing all new database connections to be kept in an

> > ArrayList
> > > in Global and then go through the ArrayList and close and remove all

of
> > the
> > > connections when Global's EndRequest method executes, but this doesn't

> > seem
> > > to do anything for me memory-wise.
> > >
> > > What is going on?!
> > >
> > > Jon
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
Jon Davis
Guest
Posts: n/a
 
      06-04-2004
Actually, eventually I do now get some of the RAM back. But I still lose
about 25MB per session between SQL Server and IIS combined that is never
regained after the Session times out.

Jon


"Jon Davis" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> > Will report here whether this (closing all open connections) clears the
> > memory leak.

>
> No it does not. Anyone know what would cause such a drastic memory leak?
> Again, lots of data is cached in the Session object, but even when the
> Session has expired, no change is made to the memory and IIS and SQL

Server
> are taking up massive amounts of RAM.
>
> Jon
>
>
> "Jon Davis" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> >
> > "Jon Davis" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> > > > I have tried forcing all new database connections to be kept in an
> > > ArrayList
> > > > in Global
> > >
> > > Oh, and I meant to say I keep them in the Session object, with the

> intent
> > to
> > > close them (and then remove them from the ArrayList) when the page

ends.
> > >
> > > How can I do this? The Session object isn't exposed in the Request_End
> > > method in Global.

> >
> > Nevermind, I already have all pages' code-behind inheret from a base

> class,
> > and I simply set up a deconstructor.
> >
> > Will report here whether this (closing all open connections) clears the
> > memory leak.
> >
> > Jon
> >
> >
> > > "Jon Davis" <(E-Mail Removed)> wrote in message
> > > news:(E-Mail Removed)...
> > > > OK I have a web app that I built that makes MANY calls to the DB in

> each
> > > > request. The app wasn't tuned for scalability so this wasn't a

> problem,
> > > but
> > > > time is too short to redesign how the database is accessed because

the
> > > data
> > > > that's being stored is time relevant and the web app will be thrown

> out
> > in
> > > a
> > > > few months. Since I try to separate the OleDb stuff from the

business
> > > logic,
> > > > I just create new database connections and trust that those

> connections
> > > will
> > > > be closed and expunged when the response ends.
> > > >
> > > > But I'm finding that between SQL Server and IIS the machine is

quickly
> > > > running out of RAM, even when the session (where I'm caching data in

a
> > > > custom user object) terminates. After 20 or so page hits (containing
> > > several
> > > > database hits per page hit) the server loses like 600MB or RAM. I

> > wouldn't
> > > > care since the access load is trivial, except that this RAM is NEVER
> > > > re-gained. Resetting SQL Server returns about 200MB and then

resetting
> > IIS
> > > > returns about 400MB. Again, this is long after the sessions have
> > > terminated.
> > > > And I host nothing in the Application collection.
> > > >
> > > > Am I wrong in my understanding that database connections

automatically
> > > close
> > > > and are destroyed when the containing object destroys itself (when

the
> > web
> > > > page's response ends)?
> > > >
> > > > I have tried forcing all new database connections to be kept in an
> > > ArrayList
> > > > in Global and then go through the ArrayList and close and remove all

> of
> > > the
> > > > connections when Global's EndRequest method executes, but this

doesn't
> > > seem
> > > > to do anything for me memory-wise.
> > > >
> > > > What is going on?!
> > > >
> > > > Jon
> > > >
> > > >
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
Chris Darnell
Guest
Posts: n/a
 
      06-05-2004
Jon, you should automatically assume that anything connecting to a database
is resource intensive. By that, I mean that it is going to take a fair
amount of processing and memory to perform and *maintain* that connectivity.
Therefore, it is common practice to only open any sort of database
connection at the point that it is needed and then release that connection
immediately after you are finished with it. Keeping the connection object
open during the entire session is definitely going to adversely affect the
memory usage of your application.

Additionally, you need to make sure that you are closing all DataReaders and
disposing of all DataSets, DataAdapters, Commands, etc.

Finally, are there other resources that you are using that are not being
closed or disposed?

Unfortunately, your statement that "time is to short to redeisgn" may be
irrelevant. If the site *has* to work, you may have to bite the bullet and
redesign how you are handling the connection... One thing you could do is
take a few pages a create a test site based on those few pages. First, make
sure that those pages continue to exhibit the same resource problems. Then,
alter just those few pages (and for goodness sake get that connection out of
the session) and see if that makes a difference in the resource usage.

Chris Darnell

"Jon Davis" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> OK I have a web app that I built that makes MANY calls to the DB in each
> request. The app wasn't tuned for scalability so this wasn't a problem,

but
> time is too short to redesign how the database is accessed because the

data
> that's being stored is time relevant and the web app will be thrown out in

a
> few months. Since I try to separate the OleDb stuff from the business

logic,
> I just create new database connections and trust that those connections

will
> be closed and expunged when the response ends.
>
> But I'm finding that between SQL Server and IIS the machine is quickly
> running out of RAM, even when the session (where I'm caching data in a
> custom user object) terminates. After 20 or so page hits (containing

several
> database hits per page hit) the server loses like 600MB or RAM. I wouldn't
> care since the access load is trivial, except that this RAM is NEVER
> re-gained. Resetting SQL Server returns about 200MB and then resetting IIS
> returns about 400MB. Again, this is long after the sessions have

terminated.
> And I host nothing in the Application collection.
>
> Am I wrong in my understanding that database connections automatically

close
> and are destroyed when the containing object destroys itself (when the web
> page's response ends)?
>
> I have tried forcing all new database connections to be kept in an

ArrayList
> in Global and then go through the ArrayList and close and remove all of

the
> connections when Global's EndRequest method executes, but this doesn't

seem
> to do anything for me memory-wise.
>
> What is going on?!
>
> Jon
>
>



 
Reply With Quote
 
Jon Davis
Guest
Posts: n/a
 
      06-08-2004
I only put the connections in the section because that is the shortest term
collection that I can keep around across all pages. I suppose I could put it
as a static class somewhere. Same difference, though, I am, storing every
connection in an arraylist, and at the termination of every page (through a
parent class) I go through the list and close and delete everything,
basically clearing out the arraylist.

It doesn't seem to change much.

Again I ask, don't Connections and DataReaders close automatically when
destroyed?

Jon


"Chris Darnell" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Jon, you should automatically assume that anything connecting to a

database
> is resource intensive. By that, I mean that it is going to take a fair
> amount of processing and memory to perform and *maintain* that

connectivity.
> Therefore, it is common practice to only open any sort of database
> connection at the point that it is needed and then release that connection
> immediately after you are finished with it. Keeping the connection object
> open during the entire session is definitely going to adversely affect the
> memory usage of your application.
>
> Additionally, you need to make sure that you are closing all DataReaders

and
> disposing of all DataSets, DataAdapters, Commands, etc.
>
> Finally, are there other resources that you are using that are not being
> closed or disposed?
>
> Unfortunately, your statement that "time is to short to redeisgn" may be
> irrelevant. If the site *has* to work, you may have to bite the bullet

and
> redesign how you are handling the connection... One thing you could do is
> take a few pages a create a test site based on those few pages. First,

make
> sure that those pages continue to exhibit the same resource problems.

Then,
> alter just those few pages (and for goodness sake get that connection out

of
> the session) and see if that makes a difference in the resource usage.
>
> Chris Darnell
>
> "Jon Davis" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > OK I have a web app that I built that makes MANY calls to the DB in each
> > request. The app wasn't tuned for scalability so this wasn't a problem,

> but
> > time is too short to redesign how the database is accessed because the

> data
> > that's being stored is time relevant and the web app will be thrown out

in
> a
> > few months. Since I try to separate the OleDb stuff from the business

> logic,
> > I just create new database connections and trust that those connections

> will
> > be closed and expunged when the response ends.
> >
> > But I'm finding that between SQL Server and IIS the machine is quickly
> > running out of RAM, even when the session (where I'm caching data in a
> > custom user object) terminates. After 20 or so page hits (containing

> several
> > database hits per page hit) the server loses like 600MB or RAM. I

wouldn't
> > care since the access load is trivial, except that this RAM is NEVER
> > re-gained. Resetting SQL Server returns about 200MB and then resetting

IIS
> > returns about 400MB. Again, this is long after the sessions have

> terminated.
> > And I host nothing in the Application collection.
> >
> > Am I wrong in my understanding that database connections automatically

> close
> > and are destroyed when the containing object destroys itself (when the

web
> > page's response ends)?
> >
> > I have tried forcing all new database connections to be kept in an

> ArrayList
> > in Global and then go through the ArrayList and close and remove all of

> the
> > connections when Global's EndRequest method executes, but this doesn't

> seem
> > to do anything for me memory-wise.
> >
> > What is going on?!
> >
> > Jon
> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
List of free web site design, web site backgrounds, web site layoutsresources cyber XML 1 12-25-2007 11:48 PM
Free web site design, web site backgrounds, web site layoutsresources cyber HTML 0 12-24-2007 04:26 PM
List of free web site design, web site backgrounds, web site layoutsresources cyber HTML 0 12-21-2007 03:47 PM
List of free web site design, web site backgrounds, web site layoutsweb sites cyber HTML 1 12-19-2007 09:07 AM
Memory leak in ASP.NET web site Jon Davis ASP .Net 18 06-09-2004 02:58 PM



Advertisments