Ticket #1276 (closed enhancement: fixed)

Opened 2 years ago

Last modified 22 months ago

Memory leaks suggestion

Reported by: colnector Owned by: romanb
Priority: minor Milestone: 1.1.0-ALPHA1
Component: Query/Hydration Version: 1.0.2
Severity: Keywords:
Cc: Has Test: no
Status: Pending Core Response Has Patch: no

Description

Currently, free() method of DoctrineQuery? needs to be used to prevent some of the memory leaks, I find the syntax inconvenient . I suggest to replace this syntax

            $q = Doctrine_Query::create()
                ->from($classname.' c')
                ->leftJoin('c.Translation t INDEXBY t.lang')
                ->where('t.lang = ? AND t.name = ? '.$sAddWhere, array($lang, $name));
            $existing = $q->fetchOne(array(), Doctrine::HYDRATE_ARRAY);
            $q->free(true);

to the following:

            $existing  = Doctrine_Query::create()
                ->from($classname.' c')
                ->leftJoin('c.Translation t INDEXBY t.lang')
                ->where('t.lang = ? AND t.name = ? '.$sAddWhere, array($lang, $name))
                ->fetchOne(array(), Doctrine::HYDRATE_ARRAY_FREE);

Using the parameter HYDRATE_ARRAY_FREE would mean free() is called after hydration and thus the syntax stays clearer. Other options to solved this issue could be another parameter to the execute() method or a global setting for Doctrine.

Change History

Changed 2 years ago by chorizo

The memory leak is a serious problem for me, since I need to process long running jobs, and run a large PHPUnit test suite.

If the global setting "free after execute()/count()" can't be provided, can a postQuery trigger be created that passes the query object to the event as the invoker? It looks like there is a preQuery event in the code that isn't in the documentation, but no postQuery event

Changed 2 years ago by anonymous

  • milestone New deleted

Milestone New deleted

Changed 22 months ago by jwage

  • version changed from 0.11.0 to 1.0.2
  • milestone set to 1.1.0

Changed 22 months ago by colnector

The article  Optimize PHP memory usage: eliminate circular references may be helpful for the memory leaks.

Changed 22 months ago by jwage

  • status changed from new to closed
  • resolution set to fixed

In r5018 this was fixed.

Changed 22 months ago by colnector

Could you please advise as on how to use ATTR_AUTO_FREE_QUERY_OBJECTS ? I'm using sfDoctrinePlugin

Note: See TracTickets for help on using tickets.