I'm using MySQL, but my dbi (Server version 3.22.32) is creating a new
reference for each fetchrow_hashref. So this was the reason of my leak. I'm
now binding my columns to a reference and using fetch. This is clearly the
best way (for me)
With the following code i had an "Out of memory!" error:
$query = $dbh->prepare("SELECT * FROM mytable");
$query->execute;
while( $hash_ref = $query->fetchrow_hashref ) { ... }
It didn't matter if the while contained something or nothing... the memory
usage kept growing with each row it fetched. He had to fetch about 300.000
rows ... It began at 5MB and quit at +/- 80MB.
Now i'm doing things like this:
my ( $id, $name, $myfield );
$query = $dbh->prepare("SELECT id, name, myfield FROM mytable");
$query->execute;
$query->bind_col(1, \$id);
$query->bind_col(2, \$name);
$query->bind_col(3, \$myfield);
while( $query->fetch ) {
## doing something with $id, $name and $myfield
}
This way the memory usage stays on 25MB the whole runtime.
So thanks for the tips everyone
Groetjes,
Tiele Declercq [ [EMAIL PROTECTED] ]
---
Projectleider Start.be
http://start.be
> Two bits of information are still missing. What DBD is the problem
> happening under? What's the code look like (post an example)? I
> would think that if the DBI had a massive memory leak (30MB), there
> would be many more complaints. My guess would be either a bad
> driver or somehow, that returned hashref is being used in such a
> way that it isn't garbage collection (stuck in an array, put in an
> object, etc.)
>
> * Philip Molter
> * Texas.net Internet
> * http://www.texas.net/
> * [EMAIL PROTECTED]
>
>