From ded721966f7a4ba73a82f08cf14637f59faec1b6 Mon Sep 17 00:00:00 2001 From: feyu Date: Fri, 26 Apr 2024 09:07:58 -0700 Subject: [PATCH] Call gc.collect() multiple times in unit test. In an upcoming change tf.Tensor is switching to proper Python GC. It need several calls to gc.collect() to break reference cycles. PiperOrigin-RevId: 628422487 --- .../layers/internal/distribution_tensor_coercible_test.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tensorflow_probability/python/layers/internal/distribution_tensor_coercible_test.py b/tensorflow_probability/python/layers/internal/distribution_tensor_coercible_test.py index feed13fb68..68932e5f95 100644 --- a/tensorflow_probability/python/layers/internal/distribution_tensor_coercible_test.py +++ b/tensorflow_probability/python/layers/internal/distribution_tensor_coercible_test.py @@ -305,10 +305,14 @@ def testTypeObjectLeakage(self): # These weakrefs could potentially come from tf.function.variables. dist = layer(x) gc.collect() + gc.collect() + gc.collect() before_objs = len(gc.get_objects()) for _ in range(int(1e2)): dist = layer(x) gc.collect() + gc.collect() + gc.collect() after_objs = len(gc.get_objects()) del dist