main icon indicating copy to clipboard operation
main copied to clipboard

Need to clear .NET exception object after catching exception

Open ironpythonbot opened this issue 11 years ago • 0 comments

The exception object for the except block is staying alive and keeping a traceback frame alive. The tracebackf rame includes the just_numbers locals. We should null out the exception object so that the memory is available for collection.


      def coroutine():
            just_numbers = range(1,1000000)
            def inner_method():
                return just_numbers
            yield None
            raise Exception("some exception") # comment out this line to make the test not work
        from System import GC
        def get_memory():
            for _ in xrange(4):
                GC.Collect()
                GC.WaitForPendingFinalizers()
            return GC.GetTotalMemory(True)/1e6
        before = get_memory()
        crt = coroutine()
        try:
            crt.next()
            crt.next()
        except:
            pass
        crt = None
        after = get_memory()
        self.assert_(after-before > 10,'There should be a memory leak in this case.before=%s after=%s' % (before,after))

Work Item Details

Original CodePlex Issue: Issue 26244 Status: Active Reason Closed: Unassigned Assigned to: Unassigned Reported on: Feb 18, 2010 at 4:14 PM Reported by: dinov Updated on: Feb 22, 2013 at 2:10 AM Updated by: jdhardy

ironpythonbot avatar Dec 09 '14 17:12 ironpythonbot