From 92dcd5142fd1d6287eb1961ff79fb145adf8446c Mon Sep 17 00:00:00 2001
From: catch <catch@35733.no-reply.drupal.org>
Date: Tue, 30 Jun 2020 14:34:57 +0100
Subject: [PATCH] Issue #3142893 by hchonov, Raunak.singh, kishor_kolekar,
 alexpott, tstoeckler, catch, kfritsche, johnwebdev: Memory leak - typed data
 prototypes for field items are not re-used like intended

(cherry picked from commit ce5d85281b53bb683c6e0c9cdd27a14368584091)
---
 core/lib/Drupal/Core/TypedData/TypedDataManager.php | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/core/lib/Drupal/Core/TypedData/TypedDataManager.php b/core/lib/Drupal/Core/TypedData/TypedDataManager.php
index 9ac018c37efd..aab5850ada17 100644
--- a/core/lib/Drupal/Core/TypedData/TypedDataManager.php
+++ b/core/lib/Drupal/Core/TypedData/TypedDataManager.php
@@ -169,7 +169,15 @@ public function getPropertyInstance(TypedDataInterface $object, $property_name,
       $parts[] = json_encode($settings);
     }
     // Property path for the requested data object.
-    $parts[] = $object->getPropertyPath() . '.' . $property_name;
+    $parts[] = $object->getPropertyPath();
+    // Only property instances of complex data types should be cached by the
+    // property name, as they represent different properties. Properties of list
+    // data types are the items of the list and the property name represents
+    // only the delta in that list and not an unique property, which is why all
+    // items should use the same prototype.
+    if ($object instanceof ComplexDataInterface) {
+      $parts[] = $property_name;
+    }
     $key = implode(':', $parts);
 
     // Create the prototype if needed.
-- 
GitLab