I REALLY Don't Understand this tool

Use this forum for questions on how to use .NET Memory Profiler and how to analyse memory usage.
Post Reply
ojm37a
Posts: 2
Joined: Mon Mar 21, 2011 10:37 pm

I REALLY Don't Understand this tool

Post by ojm37a » Mon Mar 21, 2011 10:41 pm

Hmmm. I made a real simple ASP.Net site with just a single call to a database, returning a dataset (checking to see if it exists in cache, but not yet adding it to cache) and I have no idea what the output of this program means! Not sure where to even start looking for memory leaks, heap fragmentation, ??? :oops:

Looking at the tutorial is not helpful since it doesn't even come close to what I have. Any way I could upload log file (or the asp.net source files) and someone could give some kind of pointers?

TIA,
Owen

ojm37a
Posts: 2
Joined: Mon Mar 21, 2011 10:37 pm

Re: I REALLY Don't Understand this tool

Post by ojm37a » Tue Mar 22, 2011 3:55 pm

OK. Here's some code (I haven't put the cache-set in yet; to see if I can figure out the output from the memory profiler):

Code: Select all

   Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
      Dim objContext As HttpContext = HttpContext.Current
      Dim objDS As DataSet = CType(objContext.Cache("Testing123"), DataSet)
      If objDS Is Nothing Then
         Using objDb As New DbUtils()
            Dim strSQL As String = "SELECT * FROM v2_article art INNER JOIN v2_Item itm ON art.item_id=itm.item_id  WHERE active = 1 AND start_date > '1/1/2005' ORDER BY start_date desc"
            objDS = objDb.GetDataSet(strSQL, False)
         End Using
      End If

      For Each objRow As DataRow In objDS.Tables(0).Rows
         Response.Write(objRow("Headline").ToString)
         Response.Write("<br/>")
         Response.Write(objRow("start_date").ToString)
         Response.Write("<br/><br/>")
      Next

   End Sub
More Code:

Code: Select all

Imports Microsoft.VisualBasic
Imports System.Data.SqlClient
Imports System.Data


Public Class DbUtils
   Implements IDisposable

   Private objConn As SqlConnection
   Private strConnectionString As String = ""

   Public Sub New()
      strConnectionString = "server=SQL_ServerName;UID=UserID;PWD=Password;DATABASE=am;pooling=true"
      objConn = New SqlConnection(strConnectionString)
      objConn.Open()
   End Sub

   Public Function GetDataSet(ByVal strSQL As String, ByVal booIsStoredProc As Boolean) As DataSet
      Dim objAdapter As SqlDataAdapter
      Dim objCommand As SqlCommand
      Dim objDataSet As DataSet

      objCommand = New SqlCommand(strSQL, objConn)

      objCommand.CommandTimeout = 3000
      If booIsStoredProc Then
         objCommand.CommandType = Data.CommandType.StoredProcedure
      Else
         objCommand.CommandType = Data.CommandType.Text
      End If
      objAdapter = New SqlDataAdapter(objCommand)

      objDataSet = New Data.DataSet
      objAdapter.Fill(objDataSet, "DataSet")
      objCommand.Dispose()
      objAdapter.Dispose()
      Return objDataSet

   End Function

#Region "IDisposable Support"
   Private disposedValue As Boolean = False ' To detect redundant calls

   ' IDisposable
   Protected Overridable Sub Dispose(booDisposing As Boolean)
      If booDisposing Then
         Try
            objConn.Close()
            objConn = Nothing
         Catch ex As Exception
            Throw ex
         End Try
      End If
   End Sub

   ' TODO: override Finalize() only if Dispose(ByVal disposing As Boolean) above has code to free unmanaged resources.
   Protected Overrides Sub Finalize()
      ' Do not change this code.  Put cleanup code in Dispose(ByVal disposing As Boolean) above.
      Dispose(False)
      MyBase.Finalize()
   End Sub

   ' This code added by Visual Basic to correctly implement the disposable pattern.
   Public Sub Dispose() Implements IDisposable.Dispose
      ' Do not change this code.  Put cleanup code in Dispose(ByVal disposing As Boolean) above.
      Dispose(True)
      GC.SuppressFinalize(Me)
   End Sub
#End Region

End Class

(The dataset returned has about a thousand rows in it).

So, with this code, the output from the memory profiler (using the WebDev.WebServer Version 4) makes no sense: seems to have a bunch of memory leaks, but I can't figure out how to see what they are. Some of the concepts are just not making sense yet.

I run the asp page and take a snapshot.
Then I run it again (F5 on webpage) and take another snapshot.
Then I change the dropdown in the "Types" windows to "With additional instances (delta >0)" and I have about 25 lines all with the ".net" image in the 1st column.
The 1st line is "System" "Styring" with 6003 total, 74 new, 21 removed, delta 53, total 465574, etc....
If I double click on this, Allocation stacks is 1 of 1062. Sorting by the instance column and double clicking brings up the "Type Instance Details" where the instance graph is. Makes no sense to me... Not sure what any of it means.

Ideas?

Where should I be looking for memory leaks? What should I be looking for? What does it mean?

Thanks,
Owen

Andreas Suurkuusk
Posts: 1029
Joined: Wed Mar 02, 2005 7:53 pm

Re: I REALLY Don't Understand this tool

Post by Andreas Suurkuusk » Wed Mar 23, 2011 11:57 am

Even though the tutorials are very old, I believe that tutorial 2 and 3 still provide relevant information. However in your test case there is probably no memory leak or other memory usage problem. The new instances you see when you collect the second snapshot is most likely caused by the database connection and connection pooling. If possible, try to identify new instances of types that you have knowledge about (e.g. types you have written yourself). The instance details view and especially the instance graph will provide you with information about how the instance was created and how it is prevented from being garbage collected. If you are looking at a new string instance related to connection pooling, most or all of the instances in the graph will be part of the .NET framework. This makes it harder to get an understanding of what the graph represents.

Unfortunately, the documentation has not been updated for version 4.0 of the profiler, but you can get some imformation about the instance graph on the preview page.
Best regards,

Andreas Suurkuusk
SciTech Software AB

Post Reply

Who is online

Users browsing this forum: No registered users and 37 guests