Re: DB_DataObject eats all my memory
| From: | Sven Lankes | Date: | Mon, 25 Oct 2004 21:46:50 +0000 |
| Subject: | Re: DB_DataObject eats all my memory | ||
| References: | 1 2 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-15102@lists.php.net to get a copy of this message | ||
On Mon, Oct 25, 2004 at 01:02:54PM -0700, Justin Patrin wrote:
>> I have a script where I'm doing a lot of sql queries.
>> This script eats memory until it's killed by the OOM-Killer
>> at some point (using much more than 1GB).
>> DB_DataObjects seems to be at fault.
>> I have created a very simple testcase:
>>> for ($i = 1; $i < 50000; $i++) {
> maybe unset($test); here?
Doesn't change anything.
> Perhaps DB_DO is storing the queries and results in its globals. Make
> sur eyou turn off its history options.
If it does it is not documented and I cannot find it in the source
either. But - browsing the source I found this:
* Free global arrays associated with this object.
* * Note: as we now store resultfields in a global, it is
* never freed, if you do alot of calls to find(),
* memory will grow gradually.
And now that I know it's there I also find free() in the apidoc.
Running my testcase with free() seems to improve the situation
a little. DB_O is still eating memory - could be a little less now.
I then tried using free() inside the script that started all the
trouble. That script uses a lot of different DBOs and (to make things
worse) they're nested in one case.
The script stopped working. My guess on why it stopped working is
that DBO seems to be deleting the database-connections of all
DBO instances. This is the free() function:
> function free() {
> global $_DB_DATAOBJECT;
> if (isset($_DB_DATAOBJECT['RESULTFIELDS'][$this->_DB_resultid])) {
> unset($_DB_DATAOBJECT['RESULTFIELDS'][$this->_DB_resultid]);
> }
> if (isset($_DB_DATAOBJECT['RESULTS'][$this->_DB_resultid])) {
> unset($_DB_DATAOBJECT['RESULTS'][$this->_DB_resultid]);
> }
> // this is a huge bug in DB!
> $_DB_DATAOBJECT['CONNECTIONS'][$this->_database_dsn_md5]->num_rows =
> array();
> }
I'm not sure if I'm interpreting this right but I know for sure that
the outer loop in my script stopped working as soon as I inserted
a free() for a dbo that is only used in the inner loop of my script.
Maybe I have to rewrite everything using plain old php/pg commands.
--
mfg sven lankes
megabit informationstechnik