Unit test failures with Python 3.12 and gcc
Building with debug enabled makes the tests pass. This is an indication that there is a programming error causing undefined behaviour. Are you satisfied with the resolution of your issue?
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=Yes&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/63012">Yes</a>
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=No&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/63012">No</a>

### Issue type

Bug

### Have you reproduced the bug with TensorFlow Nightly?

Yes

### Source

source

### TensorFlow version

git HEAD

### Custom code

No

### OS platform and distribution

Ubuntu 20.04

### Mobile device

n/a

### Python version

3.12.1

### Bazel version

6.5.0

### GCC/compiler version

10.2.1

### CUDA/cuDNN version

n/a

### GPU model and memory

n/a

### Current behavior?

The following tests fail
//tensorflow/python/eager:backprop_test_cpu
//tensorflow/python/eager/polymorphic_function:tracing_compilation_test
//tensorflow/python/eager:forwardprop_test_cpu
//tensorflow/python/saved_model:load_test_cpu
//tensorflow/python/eager/polymorphic_function:polymorphic_function_test_cpu

### Standalone code to reproduce the issue

```shell
bazel test --test_timeout=500,900,3000,-1 --copt=-flax-vector-conversions --test_env=TF2_BEHAVIOR=1 --define=tf_api_version=2 --test_size_filters=small,medium --test_lang_filters=py,cc --test_output=errors --verbose_failures=true --notest_verbose_timeout_warnings --action_env=PYTHON_BIN_PATH=/usr/local/bin/python3 --test_env=PORTSERVER_ADDRESS=@unittest-portserver --build_tag_filters=-no_oss,-oss_excluded,-oss_serial,-v1only,-benchmark-test,-no_aarch64,-gpu,-tpu,-no_oss_py39,-no_oss_py310 --test_tag_filters=-no_oss,-oss_excluded,-oss_serial,-v1only,-benchmark-test,-no_aarch64,-gpu,-tpu,-no_oss_py39,-no_oss_py310 --build_tests_only -- //tensorflow/... -//tensorflow/compiler/tf2tensorrt/... -//tensorflow/core/tpu/... -//tensorflow/go/... -//tensorflow/java/... -//tensorflow/python/integration_testing/... -//tensorflow/tools/toolchains/... -//tensorflow/lite/...
```


### Relevant log output

```shell
FAIL: test_functions_cleaned_LoadWithPython (__main__.SingleCycleTests)
SingleCycleTests.test_functions_cleaned_LoadWithPython
test_functions_cleaned_LoadWithPython(use_cpp_bindings=False)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/andrew/src/tf_test/tensorflow-git/bazel-ci_build-cache/.cache/bazel/_bazel_andrew/eab0d61a99b6696edb3d2aff87b585e8/execroot/org_tensorflow/bazel-out/aarch64-opt/bin/tensorflow/python/saved_model/load_test_cpu.runfiles/absl_py/absl/testing/parameterized.py", line 314, in bound_param_test
    return test_method(self, **testcase_params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/andrew/src/tf_test/tensorflow-git/bazel-ci_build-cache/.cache/bazel/_bazel_andrew/eab0d61a99b6696edb3d2aff87b585e8/execroot/org_tensorflow/bazel-out/aarch64-opt/bin/tensorflow/python/saved_model/load_test_cpu.runfiles/org_tensorflow/tensorflow/python/framework/test_util.py", line 823, in decorator
    assert not obj_count_by_type, (
AssertionError: The following objects were newly created: Counter({'list': 330, 'Operation': 270, 'TensorShape': 147})

----------------------------------------------------------------------
Ran 2 tests in 1.571s

FAILED (failures=1, skipped=1)
```
