Re: Possible memory leak using $sth->{NAME} ?
- From: Tim.Bunce@xxxxxxxxx (Tim Bunce)
- Date: Tue, 6 Jun 2006 13:02:02 +0100
On Mon, Jun 05, 2006 at 07:51:22PM -0700, David Brewer wrote:
OK, I have pared my problem down to a small test script and I've cut
away a lot of the modules I'm using that don't seem to be part of the
issue. The test script is included at the end of this message.
Thanks.
This small script doesn't leak much memory, but it's surprising to me
that it leaks at all. Essentially, I just connect to a database and
then disconnect from it, and Apache::Leak reports that this process
leaks 1 SV. If I add a simple query then Apache::Leak reports I leak 4 SVs.
'leaks' from one-off calls are rarely real leaks, they're often just
internal caching of one kind or another.
Real leaks leak in proportion to the number of calls made. I'd expect
you to be able to say something like "each call to foo leaks N scalars"
(because 100 calls leak X and 101 calls leak X+N).
Can you check for that? And can you also try a different driver or two?
Tim.
I am using DBI 1.50 with DBD::ODBC 1.13. This is on a Windows XP.
machine, using ActivePerl 5.8.8 (I was using 5.8.7 previously with the
same issue). I am talking to a MSSQL Server 2000 database.
##################################
use strict;
use warnings;
use DBI;
my $dsn = qq{DBI:ODBC:driver={SQL
Server};Server=SERVERNAME;database=DBNAME;uid=DBUSER;pwd=PASSWORD;};
my $options = { RaiseError => 1 } ;
use Apache::Leak;
leak_test {
my $dbd = DBI->connect($dsn, $options);
$dbd->disconnect();
};
##################################
On 6/2/06, David Brewer <david.brewer@xxxxxxxxx> wrote:
I am having what appears to a memory leak problem on a mod_perl
project I am working on. On the worst case web page (a search results
page) I am leaking an average of about 160k per page load! I think
I've finally isolated the problem and it appears to be related to DBI.
It's very possible that I am doing something wrong to cause the
problem. :-)
First of all, some version and module information. I am using DBI
1.50 with DBD::ODBC 1.13. I am using persistent database connections
via the Apache::DBI module. The project is using mod_perl and
Apache::ASP.
I isolated the problem by commenting out great swaths of code until
the problem went away, and then slowly adding them back in until it
reappeared. My first thought was that it had something to do with
fetchrow_hashref. I have a loop like this:
while ($row = $sth->fetchrow_hashref) {
# do stuff here
}
All of the functionality inside the loop has been commented, but my
memory leak still happens. However, if I comment the loop entirely,
the leak goes away (well, about 158k of it at least!).
If I replace the loop with something like:
while ($row = $sth->fetchrow_arrayref) {
# do stuff here
}
... no leak. I need to get at some of the column names, though, so I
added this line before the loop:
my $column_names = $sth->{NAME};
... and the leak was back! It stays even if I don't save the column
names into a variable, but just touch them:
$sth->{NAME};
In fact, it even stays if I remove the loop entirely and just include
the line above! Any ideas why this might be happening and what I
could do to fix it or work around it? Is there possibly something I'm
doing wrong here?
My next step is going to be to try to make some kind of simple test
outside of the framework of my web probject that reproduces the same
behavior. I'll post that here when I have it.
Thanks in advance for any insight,
David Brewer
- Follow-Ups:
- Re: Possible memory leak using $sth->{NAME} ?
- From: David Brewer
- Re: Possible memory leak using $sth->{NAME} ?
- References:
- Possible memory leak using $sth->{NAME} ?
- From: David Brewer
- Re: Possible memory leak using $sth->{NAME} ?
- From: David Brewer
- Possible memory leak using $sth->{NAME} ?
- Prev by Date: Re: regular expresions
- Next by Date: Re: Possible memory leak using $sth->{NAME} ?
- Previous by thread: Re: Possible memory leak using $sth->{NAME} ?
- Next by thread: Re: Possible memory leak using $sth->{NAME} ?
- Index(es):
Relevant Pages
|