Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

ASP.Net AJAX Slide show extender uses over 1GB of RAM

Posted on 2010-09-13
4
Medium Priority
?
341 Views
Last Modified: 2012-08-13
Hi

I've writen a galery for my website using the AJAX slide show extender.  The way the site works basically is that it has a tree view which contains users names and the category they've uploaded pics into.  if you click the user it shows all images that user has uploaded and if you click the category it shows pic the user has uploaded for that category.

I store the Pic info in a mssql DB and add piccs to the slide showfrom this.

My problem is when you click on a folder the RAM the browser is using (IE8)  starts to go up.  After 10 sliddes its up to 200MB and soon it gets upto 1GB and the pics arnt displayed any more.

My Code for building the slide show is below

Can any one help?

Thanks

Brasso


<System.Web.Services.WebMethod()> _
      <System.Web.Script.Services.ScriptMethod()> _
    Public Shared Function GetSlides(ByVal contextKey As String) As AjaxControlToolkit.Slide()


        Dim querystr As String = contextKey
        Dim SQLCon3 As New SqlClient.SqlConnection
        Dim SQLCmd3 As New SqlClient.SqlCommand

        'Find out what path is being used e.g Public or public/user or public/user/category
        SQLCon3.ConnectionString = System.Configuration.ConfigurationManager.AppSettings("SiBrassoCon")
        SQLCon3.Open()
        SQLCmd3.CommandText = "Select len('" & querystr & "') - len(replace('" & querystr & "', '/', '')) "
        SQLCmd3.Connection = SQLCon3

        Dim reader3 As SqlClient.SqlDataReader = SQLCmd3.ExecuteReader()
        reader3.Read()

        'Find out how may slides there are for the above selection
        Dim SQLCon2 As New SqlClient.SqlConnection
        Dim SQLCmd2 As New SqlClient.SqlCommand
        SQLCon2.ConnectionString = System.Configuration.ConfigurationManager.AppSettings("SiBrassoCon")
        SQLCon2.Open()

        If reader3(0) = 5 Then
            SQLCmd2.CommandText = ("SELECT  COUNT(Cat_ID) as cnt FROM Pic_Cats INNER JOIN Pics ON Pic_Cats.Cat_ID = Pics.Pic_Cat where Pic_User = (SUBSTRING('" & querystr & "',17,(CHARINDEX('/','" & querystr & "',17))-17)) and Cat_Name = SUBSTRING('" & querystr & "',(CHARINDEX('/','" & querystr & "',17)+1), (CHARINDEX('/','" & querystr & "',(CHARINDEX('/','" & querystr & "',17)+1)))- (CHARINDEX('/','" & querystr & "',17)+1) )  Group by Pic_Cat ")

        Else
            If reader3(0) = 4 Then
                SQLCmd2.CommandText = ("SELECT  COUNT(Cat_ID) as cnt FROM Pic_Cats INNER JOIN Pics ON Pic_Cats.Cat_ID = Pics.Pic_Cat where Pic_User = (SUBSTRING('" & querystr & "',17,(CHARINDEX('/','" & querystr & "',17))-17))  Group by Pic_User")
            Else
                SQLCmd2.CommandText = ("SELECT  COUNT(Cat_ID) as cnt FROM Pic_Cats INNER JOIN Pics ON Pic_Cats.Cat_ID = Pics.Pic_Cat ")
            End If
        End If



        SQLCmd2.Connection = SQLCon2
        Dim reader2 As SqlClient.SqlDataReader = SQLCmd2.ExecuteReader()

        reader2.Read()

        'Apply above number of slides to slide show
        Dim imgSlide(reader2(0).ToString) As AjaxControlToolkit.Slide

        'Create Dataset with slide info in it
        Dim SQLCon As New SqlClient.SqlConnection
        Dim SQLCmd As New SqlClient.SqlCommand

        SQLCon.ConnectionString = System.Configuration.ConfigurationManager.AppSettings("SiBrassoCon")
        Dim Ds As New Data.DataSet
        SQLCon.Open()
        If reader3(0) = 5 Then
            SQLCmd.CommandText = ("SELECT  Row_Number() OVER(order by Pic_ID) as rowID,     Pics.Pic_ID, Pics.Pic_Path, Pics.Pic_User + ' ' + Pic_Cats.Cat_Name AS Expr1, Pics.Pic_Disc FROM Pic_Cats INNER JOIN Pics ON Pic_Cats.Cat_ID = Pics.Pic_Cat where Pic_User = (SUBSTRING('" & querystr & "',17,(CHARINDEX('/','" & querystr & "',17))-17)) and Cat_Name = SUBSTRING('" & querystr & "',(CHARINDEX('/','" & querystr & "',17)+1), (CHARINDEX('/','" & querystr & "',(CHARINDEX('/','" & querystr & "',17)+1)))- (CHARINDEX('/','" & querystr & "',17)+1) ) ")
        Else
            If reader3(0) = 4 Then
                SQLCmd.CommandText = ("SELECT  Row_Number() OVER(order by Pic_ID) as rowID,     Pics.Pic_ID, Pics.Pic_Path, Pics.Pic_User + ' ' + Pic_Cats.Cat_Name AS Expr1, Pics.Pic_Disc FROM Pic_Cats INNER JOIN Pics ON Pic_Cats.Cat_ID = Pics.Pic_Cat where Pic_User = (SUBSTRING('" & querystr & "',17,(CHARINDEX('/','" & querystr & "',17))-17)) ")
            Else
                SQLCmd.CommandText = ("SELECT  Row_Number() OVER(order by Pic_ID) as rowID,     Pics.Pic_ID, Pics.Pic_Path, Pics.Pic_User + ' ' + Pic_Cats.Cat_Name AS Expr1, Pics.Pic_Disc FROM Pic_Cats INNER JOIN Pics ON Pic_Cats.Cat_ID = Pics.Pic_Cat")
            End If
        End If
        SQLCmd.Connection = SQLCon
        Ds.Load(SQLCmd.ExecuteReader, LoadOption.OverwriteChanges, "Result")

        'Add Slides to slide show
        For I = 0 To Ds.Tables("Result").Rows.Count - 1
            imgSlide((Ds.Tables("Result").Rows(I).Item("rowID") - 1)) = New AjaxControlToolkit.Slide(Ds.Tables("Result").Rows(I).Item("Pic_Path"), Ds.Tables("Result").Rows(I).Item("Expr1"), Ds.Tables("Result").Rows(I).Item("Pic_Disc"))
        Next
        Return (imgSlide)

    End Function

Open in new window

0
Comment
Question by:brasso_42
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 6

Expert Comment

by:ingriT
ID: 33661309
First, try closing your readers/connections to sql;
0
 
LVL 6

Accepted Solution

by:
ingriT earned 2000 total points
ID: 33661388
with this code;
<System.Web.Services.WebMethod()> _
      <System.Web.Script.Services.ScriptMethod()> _
    Public Shared Function GetSlides(ByVal contextKey As String) As AjaxControlToolkit.Slide()
        Dim querystr As String = contextKey
        Dim sqlConnection As New SqlClient.SqlConnection
        Dim sqlCommand As New SqlClient.SqlCommand
        Dim dataSet As New Data.DataSet

        Dim sqlCommand1Result As Object
        Dim sqlCommand2Result As Object
        Dim sqlCommandText As String

        'Find out what path is being used e.g Public or public/user or public/user/category
        sqlConnection.ConnectionString = System.Configuration.ConfigurationManager.AppSettings("SiBrassoCon")
        sqlConnection.Open()
        sqlCommand.CommandText = "Select len('" & querystr & "') - len(replace('" & querystr & "', '/', '')) "
        sqlCommand.Connection = sqlConnection
        sqlCommand1Result = sqlCommand.ExecuteScalar()

        If CInt(sqlCommand1Result) = 5 Then
            sqlCommandText = "SELECT  COUNT(Cat_ID) as cnt FROM Pic_Cats INNER JOIN Pics ON Pic_Cats.Cat_ID = Pics.Pic_Cat where Pic_User = (SUBSTRING('" & querystr & "',17,(CHARINDEX('/','" & querystr & "',17))-17)) and Cat_Name = SUBSTRING('" & querystr & "',(CHARINDEX('/','" & querystr & "',17)+1), (CHARINDEX('/','" & querystr & "',(CHARINDEX('/','" & querystr & "',17)+1)))- (CHARINDEX('/','" & querystr & "',17)+1) )  Group by Pic_Cat "
        Else
            If CInt(sqlCommand1Result) = 4 Then
                sqlCommandText = "SELECT  COUNT(Cat_ID) as cnt FROM Pic_Cats INNER JOIN Pics ON Pic_Cats.Cat_ID = Pics.Pic_Cat where Pic_User = (SUBSTRING('" & querystr & "',17,(CHARINDEX('/','" & querystr & "',17))-17))  Group by Pic_User"
            Else
                sqlCommandText = "SELECT  COUNT(Cat_ID) as cnt FROM Pic_Cats INNER JOIN Pics ON Pic_Cats.Cat_ID = Pics.Pic_Cat "
            End If
        End If

        sqlCommand.CommandText = sqlCommandText
        sqlCommand2Result = sqlCommand.ExecuteScalar();

        'Apply above number of slides to slide show
        Dim imgSlide(sqlCommand2Result.ToString) As AjaxControlToolkit.Slide

        If CInt(sqlCommand1Result) = 5 Then
            sqlCommandText = ("SELECT  Row_Number() OVER(order by Pic_ID) as rowID,     Pics.Pic_ID, Pics.Pic_Path, Pics.Pic_User + ' ' + Pic_Cats.Cat_Name AS Expr1, Pics.Pic_Disc FROM Pic_Cats INNER JOIN Pics ON Pic_Cats.Cat_ID = Pics.Pic_Cat where Pic_User = (SUBSTRING('" & querystr & "',17,(CHARINDEX('/','" & querystr & "',17))-17)) and Cat_Name = SUBSTRING('" & querystr & "',(CHARINDEX('/','" & querystr & "',17)+1), (CHARINDEX('/','" & querystr & "',(CHARINDEX('/','" & querystr & "',17)+1)))- (CHARINDEX('/','" & querystr & "',17)+1) ) ")
        Else
            If CInt(sqlCommand1Result) = 4 Then
                sqlCommandText = ("SELECT  Row_Number() OVER(order by Pic_ID) as rowID,     Pics.Pic_ID, Pics.Pic_Path, Pics.Pic_User + ' ' + Pic_Cats.Cat_Name AS Expr1, Pics.Pic_Disc FROM Pic_Cats INNER JOIN Pics ON Pic_Cats.Cat_ID = Pics.Pic_Cat where Pic_User = (SUBSTRING('" & querystr & "',17,(CHARINDEX('/','" & querystr & "',17))-17)) ")
            Else
                sqlCommandText = ("SELECT  Row_Number() OVER(order by Pic_ID) as rowID,     Pics.Pic_ID, Pics.Pic_Path, Pics.Pic_User + ' ' + Pic_Cats.Cat_Name AS Expr1, Pics.Pic_Disc FROM Pic_Cats INNER JOIN Pics ON Pic_Cats.Cat_ID = Pics.Pic_Cat")
            End If
        End If
        sqlCommand.CommandText = sqlCommandText
        dataSet.Load(sqlCommand.ExecuteReader, LoadOption.OverwriteChanges, "Result")
        'Add Slides to slide show
        For I = 0 To dataSet.Tables("Result").Rows.Count - 1
            imgSlide((dataSet.Tables("Result").Rows(I).Item("rowID") - 1)) = New AjaxControlToolkit.Slide(dataSet.Tables("Result").Rows(I).Item("Pic_Path"), dataSet.Tables("Result").Rows(I).Item("Expr1"), dataSet.Tables("Result").Rows(I).Item("Pic_Disc"))
        Next
        Return (imgSlide)

        sqlConnection.Close()
    End Function

Open in new window

0
 
LVL 1

Author Comment

by:brasso_42
ID: 33666935
Hi

Thanks for the help, I have implemented the above and I still get the same issue.  Its the same with chrome and simlar with firefox, but with firfox it starts to remove some of the cache so RAM usage stays at about 400-500mb which is still massive for a 30 pic slide show.

I've been reading and looking round and there seems to be a known issue with AJAX and memory leaks on page refreshes, but I dont know enough to get my head round any of the solutions.

Can you help at all?

Thanks

Brasso

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The most up-to-date version of this article is on my Blog https://iconoun.com/blog/
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question