PIM-3556: Fix memory leak on versionning

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