symfony/symfony — Issue #2376: ACL Memory Leak
Author: KaipiYann
Created: 2011-10-10 20:00:34+00:00
State: open

Hi everybody,

Since I didn't get any answer to my post in Symfony Dev Group, Hugo H told me to post here the following memory leak problem.

I have made **a very simple batch command that you can find at the end** so you can test and check if I missed something or not.

**What does this batch ?**
It takes a very simple object (created only for testing purpose) :

```php
class TestDomainObject implements DomainObjectInterface
{
protected $id = 0;

public function __construct(){

}

public function setId($id){
$this->id = $id;
}
public function getObjectIdentifier() {
return strtoupper("TESTDO_".$this->id);
}

public function getId() {
return $this->id;
}
}
```

Then make a simple ACL creation with one ACE :

```php
protected function testUpdateACL($id)
{
$this->testDomainObject->setId($id);
$objectIdentity = ObjectIdentity::fromDomainObject($this->testDomainObject);
$acl = $this->aclProvider->createAcl($objectIdentity);
$adminIdentity = new RoleSecurityIdentity("ROLE_ADMIN");
$acl->insertObjectAce($adminIdentity, MaskBuilder::MASK_VIEW);
$this->aclProvider->updateAcl($acl);
}
```

And Iterate 30000 times on this update :

```php
for($i=0; $i<30000; $i++) {
$this->testUpdateACL($i);
if (($i % 2000) == 0) {
$output->write("Iteration =".$i." Memory = ".memory_get_usage().PHP_EOL);
}
}
```

Then just run the test taking care of no-debug option in env prod :

```php
app/console --no-debug --env="prod" acl:leak
```

**Result :**
Iteration =0 Memory = 30336888
Iteration =2000 Memory = 41741288
Iteration =4000 Memory = 57838048
Iteration =6000 Memory = 73056744
Iteration =8000 Memory = 89967144
Iteration =10000 Memory = 105108416
Iteration =12000 Memory = 119921520
Iteration =14000 Memory = 134733504
Iteration =16000 Memory = 153898744
Iteration =18000 Memory = 169364552
Iteration =20000 Memory = 184178000
Iteration =22000 Memory = 198991480
Iteration =24000 Memory = 213802848
Iteration =26000 Memory = 228772712
Iteration =28000 Memory = 243585680

Did I missed something or is it an ACL problem with use of DBAL ?
Thks
Y

## LeakAclCommand.php

```php
setName('acl:leak')
->setDescription("Test memory leak on ACL");
}

/**
* @see Command
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
try
{
$this->aclProvider = $this->getContainer()->get('security.acl.provider');
$this->testDomainObject = new TestDomainObject();
for($i=0; $i<30000; $i++) {
$this->testUpdateACL($i);
if (($i % 2000) == 0) {
$output->write("Iteration =".$i." Memory = ".memory_get_usage().PHP_EOL);
}
}
$output->write('Test Done'. PHP_EOL);
}
catch (\Exception $e)
{
$output->write(PHP_EOL.'Caught a Exception. (' . $e->getMessage() . ')' . PHP_EOL);
}

}

protected function testUpdateACL($id)
{
$this->testDomainObject->setId($id);
$objectIdentity = ObjectIdentity::fromDomainObject($this->testDomainObject);
$acl = $this->aclProvider->createAcl($objectIdentity);
$adminIdentity = new RoleSecurityIdentity("ROLE_ADMIN");
$acl->insertObjectAce($adminIdentity, MaskBuilder::MASK_VIEW);
$this->aclProvider->updateAcl($acl);
}
}

use Symfony\Component\Security\Acl\Model\DomainObjectInterface;

class TestDomainObject implements DomainObjectInterface
{
protected $id = 0;

public function __construct(){

}

public function setId($id){
$this->id = $id;
}
public function getObjectIdentifier() {
return strtoupper("TESTDO_".$this->id);
}

public function getId() {
return $this->id;
}
}
```