Doctrine 1
  1. Doctrine 1
  2. DC-904

Doctrine_Query (execute / fetchOne) memory leak

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 1.2.3
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Environment:

      Description

      I've created new symfony 1.4.8 project:

      $ ./symfony -V
      symfony version 1.4.8 (/home/marcin.dryka/htdocs/leak/lib/vendor/symfony/lib)

      $ php -v
      PHP 5.3.2-1ubuntu4.5 with Suhosin-Patch (cli) (built: Sep 17 2010 13:41:55)
      Copyright (c) 1997-2009 The PHP Group
      Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
      with Xdebug v2.1.0, Copyright (c) 2002-2010, by Derick Rethans

      and set the database schema as follows:

      $ cat config/doctrine/schema.yml
      Example:
      columns:
      col1: string(255)
      col2: string(255)
      col3: string(255)
      col4: string(255)
      col5: string(255)
      col6: string(255)

      I created a task that contains a Doctrine_query call

      (...)
      protected function execute($arguments = array(), $options = array())
      {
      // initialize the database connection
      $databaseManager = new sfDatabaseManager($this->configuration);
      $connection = $databaseManager->getDatabase($options['connection'])->getConnection();

      while(1)
      {
      $m = xdebug_memory_usage();
      $q = Doctrine_Query::create()
      ->from('Example');
      $o = $q->fetchOne();

      if (false !== $o))

      { $o->free(true); }

      unset($q, $o);

      printf("Delta: %s Value: %s\n",
      xdebug_memory_usage()-$m,
      xdebug_memory_usage()
      );
      }
      }
      (...)

      Unfortunately, memory usage is increasing:
      ./symfony leak
      Delta: 3285264 Value: 10651596
      Delta: 12944 Value: 10664448
      Delta: 12952 Value: 10677308
      Delta: 12932 Value: 10690148
      Delta: 12932 Value: 10702988
      Delta: 12932 Value: 10715828
      Delta: 12932 Value: 10728668
      Delta: 12932 Value: 10741508
      Delta: 12932 Value: 10754348
      Delta: 12932 Value: 10767188

      Tested with and without data in database - result is the same.

        Activity

        Hide
        sonic wang added a comment -

        i found this bug too.

        $rcs = $query->execute(array(),\Doctrine_Core::HYDRATE_ON_DEMAND);
        $query->free();
        //write to new table
        foreach ($rcs as $rc)

        { $new = $table->create($rc->toArray()); $new->save(); $new->free(true); //free memory $rc->free(true); }

        hydrate not cause memory leak

        bug hydrate record will cause leak

        so iterate Doctrine_collection will cause memory leak

        Show
        sonic wang added a comment - i found this bug too. $rcs = $query->execute(array(),\Doctrine_Core::HYDRATE_ON_DEMAND); $query->free(); //write to new table foreach ($rcs as $rc) { $new = $table->create($rc->toArray()); $new->save(); $new->free(true); //free memory $rc->free(true); } hydrate not cause memory leak bug hydrate record will cause leak so iterate Doctrine_collection will cause memory leak
        Hide
        Marcin Dryka added a comment -

        Changing hydration doesn't work for me. Same result for:
        HYDRATE_ON_DEMAND
        HYDRATE_RECORD
        HYDRATE_ARRAY

        Show
        Marcin Dryka added a comment - Changing hydration doesn't work for me. Same result for: HYDRATE_ON_DEMAND HYDRATE_RECORD HYDRATE_ARRAY

          People

          • Assignee:
            Jonathan H. Wage
            Reporter:
            Marcin Dryka
          • Votes:
            3 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated: