J
Jon Davis
I'm reposting this because I really need some advice.
I have a web app that makes many queries to the database on every page. In
order to save development effort, I've consolidated all database querying to
methods in a single static class, so whenever I need data, I pass a SQL
string to a method and I am passed a datareader or else individual values
(string, integer, etc).
There is a horrible memory leak in this application. Just one page load
results in a loss of about 50 MB. I COULD LIVE WITH THIS if only the memory
would be restored as soon as the web page response is finished, as I just
added another 512 MB of RAM to the server and there is never more than two
or three users hitting the site at the same time (there may be more users at
the same time, but within page load time frame there's never more than two
or three). I'm watching the Task Manager report memory usage skyrocketing
from 250 or so all the way up to 800MB in one user session, and it is never
restored until SQL Server and IIS services are restarted. SQL server takes
up about 1/3 of the excessive memory loss, and IIS takes up about 2/3 of the
excessive memory loss.
Here is what I have done to try to resolve this matter.
1. All generic functions that create datareaders to retrieve individual
values from them now forcefully close the datareader (but not necessarily
the connection).
2. All database connections and datareaders are stored into ArrayList
objects which are stored in the Session. (Dangerous, I know! ... but please
follow me.)
3. All web pages that utilize these database functions inherit from a
CommonPage class. I have created a deconstructor in CommonPage that goes
through all the objects in the connections and datareader ArrayLists in the
Session and *closes* them and removes them from the ArrayLists.
4. An "AppUser" object, stored in the Session object, had been created with
a cache so that the data retrieved from the database would remain in memory
to speed up page loads. The cache is now destroyed in the CurrentPage
deconstructor.
5. The garbage collector is executed in the deconstructor.
Nothing is being stored in the Application collection.
The end result of the above is SOME savings of RAM on the development
machine (about 20% less loss), but little no change on the server for some
reason, though I'm not sure. The development machine is running XP Pro and
the server is 2003. In any case, a person still cannot go through the entire
web site (a web-based survey) without crashing the server.
I have been pulling my hair out for a week or two trying to figure out what
the cause of this mess is. This is very important to me.
Please help, anybody!
Jon
I have a web app that makes many queries to the database on every page. In
order to save development effort, I've consolidated all database querying to
methods in a single static class, so whenever I need data, I pass a SQL
string to a method and I am passed a datareader or else individual values
(string, integer, etc).
There is a horrible memory leak in this application. Just one page load
results in a loss of about 50 MB. I COULD LIVE WITH THIS if only the memory
would be restored as soon as the web page response is finished, as I just
added another 512 MB of RAM to the server and there is never more than two
or three users hitting the site at the same time (there may be more users at
the same time, but within page load time frame there's never more than two
or three). I'm watching the Task Manager report memory usage skyrocketing
from 250 or so all the way up to 800MB in one user session, and it is never
restored until SQL Server and IIS services are restarted. SQL server takes
up about 1/3 of the excessive memory loss, and IIS takes up about 2/3 of the
excessive memory loss.
Here is what I have done to try to resolve this matter.
1. All generic functions that create datareaders to retrieve individual
values from them now forcefully close the datareader (but not necessarily
the connection).
2. All database connections and datareaders are stored into ArrayList
objects which are stored in the Session. (Dangerous, I know! ... but please
follow me.)
3. All web pages that utilize these database functions inherit from a
CommonPage class. I have created a deconstructor in CommonPage that goes
through all the objects in the connections and datareader ArrayLists in the
Session and *closes* them and removes them from the ArrayLists.
4. An "AppUser" object, stored in the Session object, had been created with
a cache so that the data retrieved from the database would remain in memory
to speed up page loads. The cache is now destroyed in the CurrentPage
deconstructor.
5. The garbage collector is executed in the deconstructor.
Nothing is being stored in the Application collection.
The end result of the above is SOME savings of RAM on the development
machine (about 20% less loss), but little no change on the server for some
reason, though I'm not sure. The development machine is running XP Pro and
the server is 2003. In any case, a person still cannot go through the entire
web site (a web-based survey) without crashing the server.
I have been pulling my hair out for a week or two trying to figure out what
the cause of this mess is. This is very important to me.
Please help, anybody!
Jon