LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Why CodeIgniter free_result dont work? (https://www.linuxquestions.org/questions/programming-9/why-codeigniter-free_result-dont-work-4175428321/)

duminhtam 09-20-2012 11:50 PM

Why CodeIgniter free_result dont work?
 
$query = $this->db->query("SELECT * FROM Website");
$websites = $query->result_array();
echo 'current mem website query:';
echo size_convert(memory_get_usage()) . " <br>";

$query->free_result();
echo size_convert(memory_get_usage()) . " <br>";

The memory did not change:(

Snark1994 09-26-2012 04:46 PM

I think you might have to call

PHP Code:

unset($query); 

for there to be any effect, but it's not something I'd be that bothered about anyway... You'd have to look at the code for whatever 'query' is to see what 'free_result' actually does to work out if the memory usage should change.

Also, use [PHP][/PHP] tags around your code to make it more readable.

johnrex 05-03-2017 05:51 AM

Quote:

Originally Posted by duminhtam (Post 4785563)
$query = $this->db->query("SELECT * FROM Website");
$websites = $query->result_array();
echo 'current mem website query:';
echo size_convert(memory_get_usage()) . " <br>";

$query->free_result();
echo size_convert(memory_get_usage()) . " <br>";

The memory did not change:(

It does not really free the results array. You may need to edit the DB driver file to unset/reset the private array which stores the results.

For example, in CodeIgniter 2.2.1, you may edit mysql_result.php (CodeIgniter-2.2.1/system/database/drivers/mysql/) to modify the free_result method as follows:

Code:

function free_result()
{
  if (is_resource($this->result_id))
  {
    mysql_free_result($this->result_id);
    $this->result_id = FALSE;
    $this->result_array = array(); //Add this line to reset the stored result
  }
}


astrogeek 05-03-2017 12:05 PM

Welcome to LQ!

You have replied to a post that has been dead for five years, and to which the OP never returned.

If you have a similar issue it is always best to start your own thread so that you can provide complete context, making the information concurrent and more useful to others, and avoiding confusion that often results from things that are similar but never really the same.

Please review the Site FAQ for guidance in general forum usage.


All times are GMT -5. The time now is 08:49 AM.