{"action":"created","issue":{"url":"https://api.github.com/repos/akeneo/pim-community-dev/issues/3928","repository_url":"https://api.github.com/repos/akeneo/pim-community-dev","labels_url":"https://api.github.com/repos/akeneo/pim-community-dev/issues/3928/labels{/name}","comments_url":"https://api.github.com/repos/akeneo/pim-community-dev/issues/3928/comments","events_url":"https://api.github.com/repos/akeneo/pim-community-dev/issues/3928/events","html_url":"https://github.com/akeneo/pim-community-dev/pull/3928","id":128834534,"number":3928,"title":"[SLA] PIM-5470: Fix memory leak on rule engine","user":{"login":"SamirBoulil","id":1826473,"avatar_url":"https://avatars.githubusercontent.com/u/1826473?v=3","gravatar_id":"","url":"https://api.github.com/users/SamirBoulil","html_url":"https://github.com/SamirBoulil","followers_url":"https://api.github.com/users/SamirBoulil/followers","following_url":"https://api.github.com/users/SamirBoulil/following{/other_user}","gists_url":"https://api.github.com/users/SamirBoulil/gists{/gist_id}","starred_url":"https://api.github.com/users/SamirBoulil/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SamirBoulil/subscriptions","organizations_url":"https://api.github.com/users/SamirBoulil/orgs","repos_url":"https://api.github.com/users/SamirBoulil/repos","events_url":"https://api.github.com/users/SamirBoulil/events{/privacy}","received_events_url":"https://api.github.com/users/SamirBoulil/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/akeneo/pim-community-dev/labels/to%20review","name":"to review","color":"5319e7"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2016-01-26T14:24:24Z","updated_at":"2016-02-04T15:18:33Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/akeneo/pim-community-dev/pulls/3928","html_url":"https://github.com/akeneo/pim-community-dev/pull/3928","diff_url":"https://github.com/akeneo/pim-community-dev/pull/3928.diff","patch_url":"https://github.com/akeneo/pim-community-dev/pull/3928.patch"},"body":"| Q                 | A\r\n| ----------------- | ---\r\n| Specs             | Yes\r\n| Behats            | n/a\r\n| Blue CI           | running\r\n| Changelog updated | Yes\r\n| Review and 2 GTM  | \r\n\r\nThis PR solves an issue we encounter with the rule engine and especially with Doctrine's `UnitOfWork.php` file.\r\n\r\nWhen we iterate over subsets of products selected by a rule, the products which the `computeChangeSet()` function returns False (that the rule does not apply on) are referenced into a doctrine's internal attribute called `$scheduledForDirtyCheck`.\r\n\r\nWhen commiting those unchanged products, Doctrine's `commit()` function makes an early return and  do not clear them from the array.\r\nAs we iterate and load more and more products the array keeps growing until a fatal error arises because no memory space is available for the process to continue.\r\n\r\nThe first solution we found to solve this issue was by listening and waiting for the doctrine's `post_flush` event to clear the `$scheduledForDirtyCheck` Doctrine's internal array.\r\nThe way it was implemented was by using listeners as well as reflection. As the `$scheduledForDirtyCheck` array is private, we use reflection to set it accessible to clear the array.\r\n\r\nThe problem with this implementation was that it was defined in it's own bundle with a new service and  we were resetting the `$scheduledForDirtyCheck` array to `[]` which can have bad consequences in the long term.\r\n\r\nWe chose to implement this fix in the `ObjectDetacher` and to make it smarter by detaching entities from the `$scheduledForDirtyCheck` array at the same time we call the usual doctrine `detach()`. \r\n\r\nSo on Flush, the entity is detached from the `$identityMap` as well as from the `$scheduledForDirtyCheck`.\r\n\r\nI opened an issue on Doctrine's repo (https://github.com/doctrine/doctrine2/issues/5625).\r\n\r\n![Alt Text](http://i.giphy.com/4PvpVZBoNpuDe.gif)\r\n"},"comment":{"url":"https://api.github.com/repos/akeneo/pim-community-dev/issues/comments/179895383","html_url":"https://github.com/akeneo/pim-community-dev/pull/3928#issuecomment-179895383","issue_url":"https://api.github.com/repos/akeneo/pim-community-dev/issues/3928","id":179895383,"user":{"login":"skeleton","id":1131230,"avatar_url":"https://avatars.githubusercontent.com/u/1131230?v=3","gravatar_id":"","url":"https://api.github.com/users/skeleton","html_url":"https://github.com/skeleton","followers_url":"https://api.github.com/users/skeleton/followers","following_url":"https://api.github.com/users/skeleton/following{/other_user}","gists_url":"https://api.github.com/users/skeleton/gists{/gist_id}","starred_url":"https://api.github.com/users/skeleton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/skeleton/subscriptions","organizations_url":"https://api.github.com/users/skeleton/orgs","repos_url":"https://api.github.com/users/skeleton/repos","events_url":"https://api.github.com/users/skeleton/events{/privacy}","received_events_url":"https://api.github.com/users/skeleton/received_events","type":"User","site_admin":false},"created_at":"2016-02-04T15:18:33Z","updated_at":"2016-02-04T15:18:33Z","body":"gtm :("}}