Forum Moderators: open

Message Too Old, No Replies

Memory Leaks

still biting me on the tush

         

txbakers

4:38 pm on Aug 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In addition to:
  • closing connections
  • destroying objects

what else can be done to stem memory leakage?

I spent a good two hours this morning wading through a client's data because it looked like the error generated was specific to that client. I couldn't replicate it in my demo set or other clients.

When the second client called with the same issue I knew I had to reboot the server, and after that the first client's data (and all) are working fine again.

So what else can it be? What else can I look for to stem off memory leaks?

If I set an object to nothing (or null) does that also close or reclaim the memory used to create that object?

Thanks.

sharbel

7:18 pm on Aug 27, 2005 (gmt 0)

10+ Year Member



What framework are you programming in? (asp/asp.net)?

Lord Majestic

7:25 pm on Aug 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If I set an object to nothing (or null) does that also close or reclaim the memory used to create that object?

Unfortunately not -- it gives some hint to garbage collector though. I had one hell of a time with .NET dealing with memory leaks -- in this situation I highly recommend using memory leaks profiler as otherwise you will be pretty much guessing.

Thing to be very careful about is putting lots of objects into ArrayLists and Hashtables.

txbakers

8:07 pm on Aug 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I am in classic ASP.

And what is the "memory leaks profiler?"

Lord Majestic

8:19 pm on Aug 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Run a search on G for "memory .net profiler" -- out of them all I preferred Red Gate's.

Anyhow, if you are in classic ASP, then how come .NET is used? Are you using some COM calls or something like that?

txbakers

8:38 pm on Aug 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



But I'm not in .NET squire. Blimey! I don't recall saying that I were in .NET.

I'll have a poke around -G- and see what shakes.

(that's what I get for spending a Saturday afternoon watching Monty Python.....)

Lord Majestic

10:44 pm on Aug 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ouch - my bad, I scanned title of the forum and made mistake assuming you were talking about .NET. I need to sleep more :(

duckhunter

2:38 am on Aug 28, 2005 (gmt 0)

10+ Year Member



If I set an object to nothing (or null) does that also close or reclaim the memory used to create that object?

Yes, but if the object itself is running "out of process" it's possible the object itself is leaking the memory. ASP is pretty good about cleaning up in-process objects but DLL's that run out of scope can leave these type of trails if they aren't cleaning up properly after themselves.

Here's a simple example:
1) IIS creates COM-Object1 (memory allocated #1)
2) COM-Object1 creates SQL Connection (memory allocated #2)
3) IIS destroys COM-Object1 (memory space #1 reclaimed)
4) COM-Object1 goes out of scope.

What happenned here is the COM-Object1 didn't close/destroy the object it created and since it is running out of process, that SQL Connection is orphaned and in many cases the memory space allocated won't be reclaimed properly.

If there are just a few objects, you can track it down by setting up a webpage that calls it over-over again using a java refresh. As the object gets created/destroyed over and over, the memory counts should stay constant. If they decline persistently, you've found your culprit.

mrMister

7:09 pm on Aug 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



txbakers,

Have you checked for excessive Session state usage?

txbakers

9:36 pm on Aug 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



How would I do that in Classic ASP? I'm not sure how.

I do use the Session variables quite a bit

duckhunter

3:22 am on Aug 29, 2005 (gmt 0)

10+ Year Member



How many Variables per Session? Has the client experienced substantial increases in traffic since their code was written? How much has the RAM kept up with the increase in traffic?

I've done major repair to a big site that over-used Session Variables. Once the big site got, well, bigger - poof - nothing really worked very well. I love using them cause they are so easy but use them sparingly, 5-10 per, albeit 10 is a bit on the high end for my preference.

Unfortunately the early ASP books actually encouraged the use of Session variables. I remember one that showed example code of how to put a Connection Object into a Session Variable.

[edit]How to..... Using Performance Monitor, there are several metrics to view ASP/IIS usage statistics.[/edit]

aspdaddy

8:59 am on Aug 29, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Application vars are another possible cause also file uploads. Have you checked the firewall logs?

Never actualy seen memory leaks from forgetting to close the db connections, but if you enable connection pooling you will know if thats the problem or not.

sullen

9:17 am on Aug 29, 2005 (gmt 0)

10+ Year Member



5-10 per, albeit 10 is a bit on the high end for my preference

really? as long as session variables don't contain objects, then I have never had a problem with that - I use 30-40 variables on sites with heavy traffic.

I have had big problems with unclosed connections though. In particular I've had problems where users are redirected in certain circumstances before the close connection line. I don't know an easy way of checking for it other than searching every file for "response.redirect" and "response.end".

mrMister

7:28 pm on Aug 29, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It depends how much data you're storing in the session. But remember that the session data is stored in memory for each visitor and it remains active in memory for 20 minutes after a visitor has left your site.

If you're storing things like database results in Session then you're going to be consuming a lot of memory duuring busy periods.

On most of my sites I disable the session state completely except for member areas. There's quite a bit of processing overhead involved with the session. There's usually much better ways of managing state between pages depending on your application.

aspdaddy

8:33 pm on Aug 29, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




users are redirected in certain circumstances before the close connection line

I wonder about this one. I have an error handler that calls response.end and its made me think about that too.

Does response.end/re-direct actually stop a script from finishing on the server or just take control of the response object? If its the latter it shouldnt stop the objects being closed.

dataguy

9:17 pm on Aug 29, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This is one of the reasons I asked about testing if a recordset is open so it can conditionally be closed in [webmasterworld.com...]

I was referring to a recordset, but the connection object will work the same way. Now I'm coding my pages to close down the connection and recordset before a server transfer or response redirect.

txbakers

9:38 pm on Aug 29, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



users are redirected in certain circumstances before the close connection line

this one surprised me early on. I never suspected this one, but now it's part of the "redirect" routine to always control the objects.

I still get into trouble with the conditional close/null. For example, when I create an object based on another condition, I need a surefire way to close it only if it's been opened or even created.