@@ -295,6 +295,15 @@ def runtime_from_config(rtconfig):
295295 )
296296
297297
298+ def reset_protobuf_object (msg_class , msg_orig ):
299+ """Reset object to clear memory build-up."""
300+ # See: https://github.com/protocolbuffers/protobuf/issues/19674
301+ # The new message instantiation needs happen on a separate line.
302+ new_msg = msg_class ()
303+ new_msg .CopyFrom (msg_orig )
304+ return new_msg
305+
306+
298307def apply_delta (key , delta , data ):
299308 """Apply delta to specific data-store workflow and type."""
300309 # Assimilate new data
@@ -322,6 +331,12 @@ def apply_delta(key, delta, data):
322331 if field .name in CLEAR_FIELD_MAP [key ]:
323332 data_element .ClearField (field .name )
324333 data_element .MergeFrom (element )
334+ # Clear memory accumulation
335+ if key in (TASKS , FAMILIES ):
336+ data [key ][element .id ] = reset_protobuf_object (
337+ MESSAGE_MAP [key ],
338+ data_element
339+ )
325340 except KeyError as exc :
326341 # Ensure data-sync doesn't fail with
327342 # network issues, sync reconcile/validate will catch.
@@ -330,6 +345,9 @@ def apply_delta(key, delta, data):
330345 'on update application: %s' % str (exc )
331346 )
332347 continue
348+ # Clear memory accumulation
349+ if key == WORKFLOW :
350+ data [key ] = reset_protobuf_object (PbWorkflow , data [key ])
333351 # Prune data elements
334352 if hasattr (delta , 'pruned' ):
335353 # UIS flag to prune workflow, set externally.
0 commit comments