Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Memory Leak for simple ASP

Status
Not open for further replies.

lasers

Technical User
Oct 24, 2007
12
0
0
I'm trying to figure out why there is such a memory leak with a simple asp script like that shown below.
Code:
Option Explicit
dim dCon, sqlStat, rs, i
Set dCon = Server.CreateObject("ADODB.Connection")
dCon.ConnectionTimeout=20
dCon.open "Driver={SQL Server};Server=servername;Database=dbname;Uid=user;Pwd=pass;"
Set rs = Server.CreateObject("ADODB.Recordset")
rs.CursorType = 3
rs.LockType = 1

sqlStat = "select * from [Table];"
rs.open sqlStat, dCon

If Not rs.eof Then
    Do Until rs.eof
	i = i + 1
	rs.movenext
    Loop
	

End If
rs.close
Set rs = Nothing
dCon.close
Set dCon = Nothing

When I open the page, I notice in windows task manager on the server that the application that the page belongs to increases it's memory usage alot. After one load of the page, it is up to 10 mb. Why would this happen with such a simple script, even when the objects are cleaned up?
 
It could be that the recordset takes 10 megs to load and IIS may be caching the data in case you need to use it again within a short period of time.

Is this really the code you are running? I mean... it doesn't look like you are doing anything with the data except to count the number of rows returned. Is this true? If so, you can make this code run a lot faster and use significantly less memory.

Code:
Option Explicit
dim dCon, sqlStat, rs, i
Set dCon = Server.CreateObject("ADODB.Connection")
dCon.ConnectionTimeout=20
dCon.open "Driver={SQL Server};Server=servername;Database=dbname;Uid=user;Pwd=pass;"
Set rs = Server.CreateObject("ADODB.Recordset")
rs.CursorType = 3
rs.LockType = 1

sqlStat = "select [!]Count([/!]*[!]) As RowCount[/!] from [Table];"
rs.open sqlStat, dCon

i = RS.Fields.Item("RowCount").Value

rs.close
Set rs = Nothing
dCon.close
Set dCon = Nothing

With the code I show above, instead of returning the entire table to IIS, you are essentially returning a scalar value that represents the number of rows in the table.

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top