| 2842 | # theoretically increase the object's refcount to "save" it from gc, and any |
| 2843 | # already-deleted objects in the cycle would have be to restored.) |
| 2844 | def testGarbageCollected(self): |
| 2845 | # Create a graph we can delete and a weak reference to monitor if it's gc'd |
| 2846 | g = ops.Graph() |
| 2847 | g_ref = weakref.ref(g) |
| 2848 | # Create some ops |
| 2849 | with g.as_default(): |
| 2850 | a = constant_op.constant(2.0) |
| 2851 | b = constant_op.constant(3.0) |
| 2852 | c = math_ops.add(a, b) |
| 2853 | # Create a session we can delete |
| 2854 | with session.Session(graph=g) as sess: |
| 2855 | self.evaluate(c) |
| 2856 | # Delete all references and trigger gc |
| 2857 | del g |
| 2858 | del a |
| 2859 | del b |
| 2860 | del c |
| 2861 | del sess |
| 2862 | gc.collect() |
| 2863 | self.assertIsNone(g_ref()) |
| 2864 | |
| 2865 | def testRunnableAfterInvalidShape(self): |
| 2866 | with ops.Graph().as_default(): |