php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42891 mysqli_free_result not freeing memory
Submitted: 2007-10-08 15:10 UTC Modified: 2007-10-08 16:56 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: windeler at mediafinanz dot de Assigned:
Status: Not a bug Package: MySQLi related
PHP Version: 5.2.4 OS: Linux / Windows XP
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: windeler at mediafinanz dot de
New email:
PHP Version: OS:

 

 [2007-10-08 15:10 UTC] windeler at mediafinanz dot de
Description:
------------
I am using the latest stable PHP version 5.2.4 on Windows XP (SP2) and Linux (Kernel 2.6.16) and a MySQL Database version 5.0.45.

In both cases mysqli_free_result doesn't seem to free the allocated memory.

Reproduce code:
---------------
$db = new mysqli("localhost", "username", "password", "database");

for ($i = 1; $i <= 100; $i++)
{
    echo 'turn '.$i.'<br />';

    echo "before query: ".memory_get_usage(false).'<br />';

    $dbResult = $db->query("SELECT * FROM example LIMIT $i, $i");

    $row = $dbResult->fetch_assoc();

    echo "before close: ".memory_get_usage(false).'<br />';

    $dbResult->free();
    unset($dbResult);

    echo "after close: ".memory_get_usage(false).'<br /><br />';
}

Expected result:
----------------
turn 1
before query: 75624
before close: 79736
after close: 75624

turn 2
before query: 75624
before close: 79834
after close: 75624

turn 3
before query: 75624
before close: 79976
after close: 75624

[...]

turn 100
before query: 75624
before close: 79858
after close: 75624

Actual result:
--------------
turn 1
before query: 75624
before close: 79736
after close: 79872

turn 2
before query: 79872
before close: 84184
after close: 84184

turn 3
before query: 84184
before close: 84200
after close: 84240

[...]

turn 100
before query: 85360
before close: 85360
after close: 85360


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-10-08 16:56 UTC] johannes@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

memory_get_usage() only counts memory allocated by PHP and modules which use PHP\'s memory mangment routines. The libmysql allocates it\'s memory itself therefore PHP doesn\'t know about it.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 02 10:01:38 2025 UTC