According to standard Doctrine2 documentation, you need to manually clean or delete objects.
In addition to this, when profiling is enabled (as in the default dev environment). The DoctrineBundle in Symfony2 sets up several registrars that use quite a bit of memory. You can completely disable logging, but this is not required.
An interesting side effect is that registrars affect both ORM ORD and DBAL. One of the logs will result in additional memory usage for any service that uses the default logging service. Disabling all of them would be ideal in teams - since the profiler is not yet used.
Here's what you can do to turn off intensive data records while maintaining profiling in other parts of Symfony2:
$c = $this->getContainer(); /* * The default dbalLogger is configured to keep "stopwatch" events for every query executed * the only way to disable this, as of Symfony 2.3, Doctrine Bundle 1.2, is to reinistiate the class */ $dbalLoggerClass = $c->getParameter('doctrine.dbal.logger.class'); $dbalLogger = new $dbalLoggerClass($c->get('logger')); $c->set('doctrine.dbal.logger', $dbalLogger); // sometimes you need to configure doctrine to use the newly logger manually, like this $doctrineConfiguration = $c->get('doctrine')->getManager()->getConnection()->getConfiguration(); $doctrineConfiguration->setSQLLogger($dbalLogger); /* * If profiling is enabled, this service will store every query in an array * fortunately, this is configurable with a property "enabled" */ if($c->has('doctrine.dbal.logger.profiling.default')) { $c->get('doctrine.dbal.logger.profiling.default')->enabled = false; } /* * When profiling is enabled, the Monolog bundle configures a DebugHandler that * will store every log messgae in memory. * * As of Monolog 1.6, to remove/disable this logger: we have to pop all the handlers * and then push them back on (in the correct order) */ $handlers = array(); try { while($handler = $logger->popHandler()) { if($handler instanceOf \Symfony\Bridge\Monolog\Handler\DebugHandler) { continue; } array_unshift($handlers, $handler); } } catch(\LogicException $e) { /* * As of Monolog 1.6, there is no way to know if there a handler * available to pop off except for the \LogicException that thrown. */ if($e->getMessage() != 'You tried to pop from an empty handler stack.') { /* * this probably doesn't matter, and will probably break in the future * this is here for the sake of people not knowing what they're doing * so than an unknown exception is not silently discarded. */ // remove at your own risk throw $e; } } // push the handlers back on foreach($handlers as $handler) { $logger->pushHandler($handler); }
Reece45 Sep 08 '13 at 5:32 2013-09-08 05:32
source share