memory leak?

G

Guest

I noticed some disturbing memory behaviour in the w3wp.exe process running a
web app of mine. I have duplicated it into a simple web service.
Basically, every time I call this web service it adds 3K to the w3wp.exe
process and does not release it. If I call it 30,000 times it adds 100,000 K.
The total bytes allocated according to GC.gettotalmemory stays constant.

The code of the web service follows. I hope I'm missing something simple.

Public Class MemLeak
Inherits System.Web.Services.WebService


<WebMethod()> _
Public Function MemoryLeak() As Long
Dim connSQL As New OleDb.OleDbConnection()
Dim cmdSQL As New OleDb.OleDbCommand
Dim strSQL As String, strData As String
Dim i As Integer


Try
connSQL.ConnectionString = "Provider=SQLOLEDB;Data
Source=sql2005;Initial Catalog=myDB;uid=xx;pwd=xx;Encrypt=false;Connect
Timeout=30;Persist Security Info=False;"
cmdSQL.Connection = connSQL
connSQL.Open()
strSQL = "Select max(AppOptions) From Users_AppData where
len(appOptions)>255"
cmdSQL.CommandText = strSQL

' loop 4 times to amplify memory issues
For i = 1 To 4
' The string returned here is 816 char long
strData = cmdSQL.ExecuteScalar.ToString
'strData = Nothing
Next

connSQL.Close()
cmdSQL.Dispose()
connSQL.Dispose()
cmdSQL = Nothing
connSQL = Nothing

Catch ex As Exception
If connSQL.State = ConnectionState.Open Then connSQL.Close()
cmdSQL.Dispose()
connSQL.Dispose()
cmdSQL = Nothing
connSQL = Nothing
End Try


Return GC.GetTotalMemory(True)
End Function

End Class


It is running on Windows Server 2003 v 5.2.3790 SP1 Build 3790, X64
..NET 2.0.50727

Is this a coding issue or an IIS/.NET bug ?

Thanks, Andrew
 
B

bruce barker

if the gc show the same memory foot print then you are leaking unmanaged
memory. add a call to GC.Collect() just to be sure the a garbage collect
is being run. if you have lots of memory, its not done.

-- bruce (sqlwork.com)
 
G

Guest

I have tried it with a gc.collect() and it makes no difference - which makes
sense as the gc isn't showing any awareness of increased memory use.
 
G

Guest

In case any one else encounters this sort of issue.
The problem is with the SQLOLEDB provider. Used within the oledb methods it
holds all of the memory of it's read strings (at least the long strings) and
doesn't release it. More of a hemorage than a leak.
Changing to the SQLNCLI provider (or sqlclient instead of oledb)
solves/bypasses the issue.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top