title: JMS_Serializer service not working in Symfony2 - Error: Allowed memory size
body: <p>In my Controller in Symfony2 I am retrieving a collection of Blog Posts as Doctrine Entities:</p>
  
  <pre><code>$posts = $this-&gt;getDoctrine()
          -&gt;getRepository('MyBundle:Post')
          -&gt;findPostDatesAscending();
  </code></pre>
  
  <p>I dutifully installed the JMSSerializer bundle as it is supposed to work with Doctrine ORM, and called the service also in my Controller:</p>
  
  <pre><code>$serializer = $this-&gt;container-&gt;get('jms_serializer'); 
  $jsonContent = $serializer-&gt;serialize($posts, 'json');
  echo $jsonContent;
  </code></pre>
  
  <p>However, I get the following error:</p>
  
  <blockquote>
    <p>FatalErrorException: Error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 55204 bytes) in C:\wamp\www\Symfony\vendor\jms\serializer\src\JMS\Serializer\GenericSerializationVisitor.php line 58</p>
  </blockquote>
  
  <p>I tried to find this issue already, and there seems to be not much joy in getting serialization of Entities to JSON to work. I'm sure this is some sort of recursion issue, but I am pretty new to Symfony2 so am unsure of the reasons why this is the case, and in particular, how I can get these Entities/Objects into a JSON string. </p>
  
  <p>I almost forgot, my post object has a oneToMany relationship. Not sure if this is relevant:</p>
  
  <pre><code>/BlogBundle/Resources/config/doctrine/Blog.orm.yml
  MyBundle\BlogBundle\Entity\Blog:
  type: entity
  repositoryClass: MyBundle\BlogBundle\Entity\BlogRepository
  oneToMany:
      posts:
          targetEntity: Post
          mappedBy: blog
  table: null
  fields:
      id:
          type: integer
          id: true
          generator:
              strategy: AUTO
      blog:
          type: string
          length: '255'
  uniqueConstraints:
      search_idx:
          columns: blog
  lifecycleCallbacks: {  }
  </code></pre>
  
  <p>And my blog object is also mapped to an author object - typical blog set up really...</p>
  
  <p>EDIT: In response to @kix, I added exclusion code to ALL of my Entity Classes (Post, see example code below, Blog and Author), which excluded all of the objects to be serialized and STILL got the memory error. I limited the response to just one blog post, which is only linked to a blog (id and name) and author (id and name).</p>
  
  <pre><code>namespace MyBundle\BlogBundle\Entity;
  
  use Doctrine\ORM\Mapping as ORM;
  use JMS\Serializer\Annotation\ExclusionPolicy;
  use JMS\Serializer\Annotation\Expose;
  
  /**
   * The following annotations tells the serializer to skip all properties which
   * have not marked with @Expose.
   *
   * @ExclusionPolicy("all")
   */
  
  /**
   * Post
   */
  class Post
  {
       /**
        * @var integer
        */
        private $id;
        ...etc
  </code></pre>
  
  <p>Any help will be appreciated, thank-you.</p>