Welcome Guest, Not a member yet? Register   Sign In
Memory Leak HELP! [SOLVED]
#1

[eluser]Frychiko[/eluser]
Hi,

I have a callback function used in a function which parses large xml/csv feeds (up to around 200MB feeds), so it gets called tens of thousands of times during an import of a feed.

Basically when the callback function is blank, memory usage does not increase:

Code:
function import_record_handler($record)
{
return;
}

BUT...

when I make a single call using the active record db class, memory usage starts climbing.


Code:
function import_record_handler($record)
{
$exists = $this->CI->Merchant_model->get_temp_category_where(array(
        "name"             => $raw_category,
        "merchant_id"        => $this->merchant_id
    ));
return;
}

Merchant_model.php below:

Code:
function get_temp_category_where($data)
{
$this->db->where($data);    
$query = $this->db->get($this->table_temp_category);
return $query->row();
}

Memory keeps going rising until the memory limit is exhausted. Why is the memory not freed?

cheers,
Frychiko
#2

[eluser]johnwbaxter[/eluser]
$query->free_result()

http://ellislab.com/codeigniter/user-gui...sults.html
#3

[eluser]Frychiko[/eluser]
Tried that already but doesn't do anything, anyway I need to return the query so I can't do that.

The actual query result doesn't really matter, ANY call to the DB active record class will leak memory...eg:

Code:
$this->db->where($data);

Will leak memory...

So, I'm guessing something the sql queries are being stored...

I've tried setting $save_queries = FALSE in DB_driver.php that has no effect either.
#4

[eluser]Frychiko[/eluser]
Okay looks like the save_queries = FALSE is working now, must have been a cache problem. Yay!

This thing should be off by default, yikes..
#5

[eluser]zutis[/eluser]
Thanks Frychiko - AWSOME find!!! This has absolutely saved my a** late on a Friday!

Amazing - from a script getting close to 27MB of memory usage it was back to 3MB just by changing this setting.

Code:
$this->db->save_queries = FALSE;

What is it suppose to do?
#6

[eluser]@li[/eluser]
Where should I set the save_queries=false setting?
#7

[eluser]garymardell[/eluser]
To turn off save queries add
Code:
$db['default']['save_queries'] = FALSE;

Into your database.php configuration file (in the configs folder).
#8

[eluser]zutis[/eluser]
garymardell - thats handy to know.

@li - if you want to turn it off for all of the site then use the config option, if you only want to turn it off for a one off function then you can use the class variable as per my example at the top of your function.

Does anyone know what it actually does - i.e. that are we loosing out on by turning it off?
#9

[eluser]zutis[/eluser]
just found out - it enables you to build queries between different functions. so as long as you build and execute the query in the same function then it wont affect you.
#10

[eluser]Unknown[/eluser]
$this->db->save_queries = FALSE;

$db['default']['save_queries'] = FALSE;

Neither of these settings changed the default setting. I had to manually change system/database/DB_driver.php




Theme © iAndrew 2016 - Forum software by © MyBB