Memory leak

Posted on 2005-04-25
Last Modified: 2008-01-09
Hello all,

I'm running IIS 6.0 on Win2K3.

The script below pulls an image out of my (Access) database, I use the asppainter object to set the quality and then I use the binarywrite method to send it to the client's browser. After I run it, the memory usage of the w3wp.exe process increases with about 300KB and it doesn't decrease again. Since this page is called in a loop to display a lot of images the memory increases very fast.

<!--#include file="../../parameters.asp"-->

DIM bdata
DIM mypic

 STILLID = Request.Querystring("STILLID")

 set DB_CONN=server.createobject("ADODB.Connection")
 Set RS = Server.CreateObject("ADODB.Recordset")

 RS.Open SQL_STRING, DB_CONN, adOpenStatic, adLockOptimistic, adCmdText
  If Not RS.EOF Then
   If Not IsNull(RS("STILLDATA")) Then
      Set pic = CreateObject("ASPPainter.Pictures.1")
      mypic = RS("STILLDATA")
      pic.LoadStream (mypic)
      pic.SetJpegQuality 50
      pic.SetFormat 1
      bdata = pic.SaveToStream

      Response.ContentType = "image/jpeg"
      Response.BinaryWrite bdata

      mypic = ""
      bdata = ""

      Set pic=Nothing
      Set mypic = Nothing
      Set bdata = Nothing
   End If
  End If

 Set RS = Nothing
 Set DB_CONN=Nothing


Any ideas?
Question by:EyeContact
    LVL 11

    Expert Comment


    Try to convert these code inside an VB dll and run it as component services.

    LVL 2

    Author Comment

    Hi Ajai,

    I have no idea how to do that.

    Why are you suggesting this? If this can be done in plain and simple asp, why would I need to make a dll?

    LVL 15

    Expert Comment

    One very simple thing to try (which I doubt will make alot of difference) is to turn buffering off. That means that binary data will be sent to the client immediately rather than when the whole page has finished executing. Just add this line at the top of your page:

    Response.Buffer = false

    Secondly, I wouldn't do this:

    bdata = pic.SaveToStream
    Response.BinaryWrite bdata

    because you're copying the binary data into another variable before writing it out to the browser. This is completely unnecessary and only increases memory usage. Just use:

    Response.BinaryWrite pic.SaveToStream

    And one more thing: do you absolutely have to use the image component? All you're doing is setting the image quality. I guess you're doing this to make the output images smaller. Fair enough. But again, this only increases memory usage on your server. The absolute best option in terms of performance would be to write the binary data directly to the client from the database and bypass the image component altogether.

    And getting a bit off topic...

    You'll no doubt get lots of people asking you why you store the image data in a DB table rather than as a file on the file system. And this is good question :-) Do you really need to do this? This will make your DB grow enormously which with Access in particular is never a good thing.
    LVL 2

    Author Comment

    Hello deighc,

    Thanks a lot for your detailed description. Based on your advise I did some further testing and I found out that it is indeed the asppainter component that is causing the memory leak.

    I'll tell you a little more of what I am doing here.

    Users are uploading powerpoint presentations into my web application. I save the slides as TIF images in the database. Then on the next page, the user gets an overview of all slides (this is the part described above) and he can set times for each slide. The last step is to create an MPEG movie from the TIF images. After that the images will usually be deleted by the user from the database (unless he's not happy with the result (timing..) then he can make a new MPEG).
    The TIF files are obviously too big to send to the client, therefor I'm using the asppainter component to make the page load time acceptable.

    I will contact the creator of the component and see if he/they know how to fix the leak.
    If not, can you advise me another component or workaround?

    LVL 15

    Accepted Solution

    I'm not familiar with ASPPainter so I can't provide you with help or suggestions there. But I've had good luck with ASP Image from Server Objects:

    (scroll down the page a bit)

    But, as you've already suggested, I would contact the creators of your current component first since you've probably already given them some $$$.

    It's hard to think of a way of breaking up your required functionality into different steps so as to avoid your problem. If it's "simply" a memory usage issue then maybe the only guarenteed fix is to throw more RAM at your server.
    LVL 2

    Author Comment

    We didn't really solve the problem, but you took your time to help me so I accepted your answer. I emailed the asppainter guys and I hope to get a response from them soon.


    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
    I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    733 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

    Need Help in Real-Time?

    Connect with top rated Experts

    25 Experts available now in Live!

    Get 1:1 Help Now