0

On my sf 2.8 project got the following entity with self relation, used to store tourist destinations, for example a parent could be Caribe, children Jamaica, and children Kingston

class Destination
{
/**
 * @var integer
 *
 * @ORM\Column(name="id", type="integer")
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="AUTO")
 */
private $id;

/**
 * @var string
 *
 * @ORM\Column(name="name", type="string", length=255)
 * @Assert\NotBlank()
 */
private $name;

/**
 * @var \Application\ModelBundle\Entity\Destination
 *
 * @ORM\ManyToOne(targetEntity="Application\ModelBundle\Entity\Destination", inversedBy="children")
 * @ORM\JoinColumn(name="parent", referencedColumnName="id", onDelete="cascade")
 */
private $parent;

/**
 * @var \Application\ModelBundle\Entity\Destination
 *
 * @ORM\OneToMany(targetEntity="Application\ModelBundle\Entity\Destination", mappedBy="parent", cascade={"persist", "remove"})
 */
private $children;

/**
 * @var \Application\ModelBundle\Entity\User
 *
 * @ORM\ManyToOne(targetEntity="Application\ModelBundle\Entity\User", inversedBy="destinations")
 * @ORM\JoinColumn(name="user", referencedColumnName="id", onDelete="cascade")
 * @Assert\Type(type="Application\ModelBundle\Entity\User")
 */
private $user;


/**
 * @var \Application\ModelBundle\Entity\Hotel
 *
 * ORM\OneToMany(targetEntity="Application\ModelBundle\Entity\Hotel", mappedBy="touristDestination", cascade={"persist"})
 */   

private $hotels;
}

Everything works well with few records, but when i populate the entity or table with all records from a country for example (12000 records), system run out of memory, it's impossible do something, and throws this error

OutOfMemoryException in JsonSerializationVisitor.php line 29:
Error: Allowed memory size of 268435456 bytes exhausted (tried to allocate    10489856 bytes)
in JsonSerializationVisitor.php line 29

i'm running a command to load destinations from xls file, it run out of memory, never finish, and later i'm not able to do any action on my project

Maybe the problem is that symfony loads all related objects and it collapse, any ideas how to solve it?

Randy
  • 33
  • 7
  • when does this happen? when inserting? when loading one? when loading all? – LBA Apr 13 '16 at 15:58
  • i'm running a command to load destinations from xls file, it run out of memory, never finish, and later i'm not able to do any action on my project – Randy Apr 13 '16 at 16:21
  • 2
    If you run out of memory during mass import (inserts), then try batch processing: http://doctrine-orm.readthedocs.org/projects/doctrine-orm/en/latest/reference/batch-processing.html and also turn of doctrine logging: first answer in http://stackoverflow.com/questions/9699185/memory-leaks-symfony2-doctrine2-exceed-memory-limit – Miro Apr 13 '16 at 18:24
  • Do you use getChildren in your loop ? Is the repository method left/inner joining ? – Romain Bruckert Apr 14 '16 at 08:31
  • yes, i'm using getChildren, don't know witch repository method you mean? – Randy Apr 14 '16 at 15:30

0 Answers0