Skip to content

Commit

Permalink
Call gc.collect() multiple times in unit test.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rainwoodman authored and tensorflower-gardener committed Apr 26, 2024
1 parent ef5f155 commit ded7219
Showing 1 changed file with 4 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit ded7219

Please sign in to comment.