PIM-3556 (proposal-master): Fix memory leak on versionning

| Q                    | A
| -------------------- | ---
| Bug fix?             | Y
| New feature?         | N
| BC breaks?           | N
| CI currently passes? | Y
| Tests pass?          | Y
| Scenarios pass?      | Y
| Checkstyle issues?*  | N
| PMD issues?**        | N
| Changelog updated?   | N
| Fixed tickets        | PIM-3556
| DB schema updated?   | Y
| Migration script?    | Y
| Doc PR               | Y