Problem/Motivation
\Drupal\Core\Field\FieldTypePluginManager::createFieldItem()
passes the $index
of the field item as a $property_name
which leads to the generation of a new prototype for every new field item of the same field. If there are 1000 items there will be 1000 prototypes. However the typed data manager uses a prototype cache for similar typed data objects and returns a cloned object from the prototypes whenever possible. Alternating by the $index
just makes this prototype cache useless for field items and also introduces a memory leak the more items one initializes in a process, as they are never cleared by the garbage collector. This made our system of batch processing explode for a field with a lot of items and therefore I think this should be classified as a critical because of the memory leak.
Proposed resolution
Make the $property_name parameter of \Drupal\Core\TypedData\TypedDataManagerInterface::getPropertyInstance()
optional and do not pass the field item index as property name anymore from \Drupal\Core\Field\FieldTypePluginManager::createFieldItem()