diff --git a/tornado/concurrent.py b/tornado/concurrent.py
index ec68dc4f..e7b0e44e 100644
--- a/tornado/concurrent.py
+++ b/tornado/concurrent.py
@@ -234,7 +234,10 @@ class Future(object):
         if self._result is not None:
             return self._result
         if self._exc_info is not None:
-            raise_exc_info(self._exc_info)
+            try:
+                raise_exc_info(self._exc_info)
+            finally:
+                self = None
         self._check_done()
         return self._result
 
diff --git a/tornado/gen.py b/tornado/gen.py
index d7df3b52..8e6a5940 100644
--- a/tornado/gen.py
+++ b/tornado/gen.py
@@ -315,6 +315,7 @@ def _make_coroutine_wrapper(func, replace_callback):
                     future.set_exc_info(sys.exc_info())
                 else:
                     _futures_to_runners[future] = Runner(result, future, yielded)
+                yielded = None
                 try:
                     return future
                 finally:
@@ -990,6 +991,7 @@ class Runner(object):
         # of the coroutine.
         self.stack_context_deactivate = None
         if self.handle_yield(first_yielded):
+            gen = result_future = first_yielded = None
             self.run()
 
     def register_callback(self, key):
@@ -1046,10 +1048,15 @@ class Runner(object):
                     except Exception:
                         self.had_exception = True
                         exc_info = sys.exc_info()
+                    future = None
 
                     if exc_info is not None:
-                        yielded = self.gen.throw(*exc_info)
-                        exc_info = None
+                        try:
+                            yielded = self.gen.throw(*exc_info)
+                        finally:
+                            # Break up a reference to itself
+                            # for faster GC on CPython.
+                            exc_info = None
                     else:
                         yielded = self.gen.send(value)
 
@@ -1082,6 +1089,7 @@ class Runner(object):
                     return
                 if not self.handle_yield(yielded):
                     return
+                yielded = None
         finally:
             self.running = False
 
@@ -1130,8 +1138,11 @@ class Runner(object):
                 self.future.set_exc_info(sys.exc_info())
 
         if not self.future.done() or self.future is moment:
+            def inner(f):
+                f = None
+                self.run()
             self.io_loop.add_future(
-                self.future, lambda f: self.run())
+                self.future, inner)
             return False
         return True
 
diff --git a/tornado/http1connection.py b/tornado/http1connection.py
index 7ee83161..464ca4d3 100644
--- a/tornado/http1connection.py
+++ b/tornado/http1connection.py
@@ -257,6 +257,7 @@ class HTTP1Connection(httputil.HTTPConnection):
             if need_delegate_close:
                 with _ExceptionLoggingContext(app_log):
                     delegate.on_connection_close()
+            header_future = None
             self._clear_callbacks()
         raise gen.Return(True)
 
diff --git a/tornado/util.py b/tornado/util.py
index d0f83d1f..186995f3 100644
--- a/tornado/util.py
+++ b/tornado/util.py
@@ -193,7 +193,11 @@ def exec_in(code, glob, loc=None):
 if PY3:
     exec("""
 def raise_exc_info(exc_info):
-    raise exc_info[1].with_traceback(exc_info[2])
+    try:
+        raise exc_info[1].with_traceback(exc_info[2])
+    finally:
+        exc_info = None
+
 """)
 else:
     exec("""

Possible memory leak
Hi,

I have memory leaks even in "hello, world" example listed here http://www.tornadoweb.org/en/stable/

Code of tornado_memory_test.py: http://pastebin.com/BfG7Na9Z

Here is an example of a problem:
$ python tornado_memory_test.py 
No memory leaks found!
No memory leaks found!
[I 161031 18:00:54 web:1946] 200 GET /test (127.0.0.1) 0.87ms
Memory garbage detected
[gc stat]: 73 objects in garbage
Memory garbage detected
[gc stat]: 73 objects in garbage
Memory garbage detected
[gc stat]: 73 objects in garbage
[I 161031 18:01:11 web:1946] 200 GET /test (127.0.0.1) 0.73ms
Memory garbage detected
[gc stat]: 146 objects in garbage


Here is a verbose output of garbage: http://pastebin.com/BzXudRXd

$ pip freeze | grep -i tor
tornado==4.4.2

$ python -V
Python 2.7.12

Also tried on:
$ pip freeze | grep tor
tornado==4.5.dev1

$ python -V
Python 2.7.12


diff --git a/tornado/test/gen_test.py b/tornado/test/gen_test.py
index 8bbfc5fa..8102f223 100644
--- a/tornado/test/gen_test.py
+++ b/tornado/test/gen_test.py
@@ -992,6 +992,31 @@ class GenCoroutineTest(AsyncTestCase):
 
         self.finished = True
 
+    @skipNotCPython
+    def test_coroutine_refcounting(self):
+        # On CPython, tasks and their arguments should be released immediately
+        # without waiting for garbage collection.
+        @gen.coroutine
+        def inner():
+            class Foo(object):
+                pass
+            local_var = Foo()
+            self.local_ref = weakref.ref(local_var)
+            yield gen.coroutine(lambda: None)()
+            raise ValueError('Some error')
+
+        @gen.coroutine
+        def inner2():
+            try:
+                yield inner()
+            except ValueError:
+                pass
+
+        self.io_loop.run_sync(inner2, timeout=3)
+
+        self.assertIs(self.local_ref(), None)
+        self.finished = True
+
 
 class GenSequenceHandler(RequestHandler):
     @asynchronous

pip install -e .[dev]
parse_log_pytest
pytest
sphinx sphinx_rtd_theme pytest
apt-get update apt-get install -y gcc
3.6
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
alabaster==0.7.13
attrs @ file:///opt/conda/conda-bld/attrs_1642510447205/work
Babel==2.11.0
certifi==2021.5.30
charset-normalizer==2.0.12
docutils==0.18.1
idna==3.10
imagesize==1.4.1
importlib-metadata @ file:///tmp/build/80754af9/importlib-metadata_1631916693255/work
iniconfig @ file:///home/linux1/recipes/ci/iniconfig_1610983019677/work
Jinja2==3.0.3
MarkupSafe==2.0.1
more-itertools @ file:///tmp/build/80754af9/more-itertools_1637733554872/work
packaging @ file:///tmp/build/80754af9/packaging_1637314298585/work
pluggy @ file:///tmp/build/80754af9/pluggy_1615976315926/work
py @ file:///opt/conda/conda-bld/py_1644396412707/work
Pygments==2.14.0
pyparsing @ file:///tmp/build/80754af9/pyparsing_1635766073266/work
pytest==6.2.4
pytz==2025.2
requests==2.27.1
snowballstemmer==2.2.0
Sphinx==5.3.0
sphinx-rtd-theme==2.0.0
sphinxcontrib-applehelp==1.0.2
sphinxcontrib-devhelp==1.0.2
sphinxcontrib-htmlhelp==2.0.0
sphinxcontrib-jquery==4.1
sphinxcontrib-jsmath==1.0.1
sphinxcontrib-qthelp==1.0.3
sphinxcontrib-serializinghtml==1.1.5
toml @ file:///tmp/build/80754af9/toml_1616166611790/work
-e git+https://github.com/tornadoweb/tornado.git@69253c820df473407c562a227d0ba36df25018ab#egg=tornado
typing_extensions @ file:///opt/conda/conda-bld/typing_extensions_1647553014482/work
urllib3==1.26.20
zipp @ file:///tmp/build/80754af9/zipp_1633618647012/work

name: tornado
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - attrs=21.4.0=pyhd3eb1b0_0
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2021.5.30=py36h06a4308_0
  - importlib-metadata=4.8.1=py36h06a4308_0
  - importlib_metadata=4.8.1=hd3eb1b0_0
  - iniconfig=1.1.1=pyhd3eb1b0_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.3=he6710b0_2
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - more-itertools=8.12.0=pyhd3eb1b0_0
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - packaging=21.3=pyhd3eb1b0_0
  - pip=21.2.2=py36h06a4308_0
  - pluggy=0.13.1=py36h06a4308_0
  - py=1.11.0=pyhd3eb1b0_0
  - pyparsing=3.0.4=pyhd3eb1b0_0
  - pytest=6.2.4=py36h06a4308_2
  - python=3.6.13=h12debd9_1
  - readline=8.2=h5eee18b_0
  - setuptools=58.0.4=py36h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - toml=0.10.2=pyhd3eb1b0_0
  - typing_extensions=4.1.1=pyh06a4308_0
  - wheel=0.37.1=pyhd3eb1b0_0
  - xz=5.6.4=h5eee18b_1
  - zipp=3.6.0=pyhd3eb1b0_0
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - alabaster==0.7.13
      - babel==2.11.0
      - charset-normalizer==2.0.12
      - docutils==0.18.1
      - idna==3.10
      - imagesize==1.4.1
      - jinja2==3.0.3
      - markupsafe==2.0.1
      - pygments==2.14.0
      - pytz==2025.2
      - requests==2.27.1
      - snowballstemmer==2.2.0
      - sphinx==5.3.0
      - sphinx-rtd-theme==2.0.0
      - sphinxcontrib-applehelp==1.0.2
      - sphinxcontrib-devhelp==1.0.2
      - sphinxcontrib-htmlhelp==2.0.0
      - sphinxcontrib-jquery==4.1
      - sphinxcontrib-jsmath==1.0.1
      - sphinxcontrib-qthelp==1.0.3
      - sphinxcontrib-serializinghtml==1.1.5
      - urllib3==1.26.20
prefix: /opt/conda/envs/tornado

tornado/test/gen_test.py::GenCoroutineTest::test_coroutine_refcounting
tornado/test/gen_test.py::GenEngineTest::test_arguments tornado/test/gen_test.py::GenEngineTest::test_async_raise_return tornado/test/gen_test.py::GenEngineTest::test_async_raise_return_value tornado/test/gen_test.py::GenEngineTest::test_async_raise_return_value_tuple tornado/test/gen_test.py::GenEngineTest::test_bogus_yield tornado/test/gen_test.py::GenEngineTest::test_bogus_yield_tuple tornado/test/gen_test.py::GenEngineTest::test_exception_in_task_phase1 tornado/test/gen_test.py::GenEngineTest::test_exception_in_task_phase2 tornado/test/gen_test.py::GenEngineTest::test_exception_in_yield tornado/test/gen_test.py::GenEngineTest::test_exception_phase1 tornado/test/gen_test.py::GenEngineTest::test_exception_phase2 tornado/test/gen_test.py::GenEngineTest::test_future tornado/test/gen_test.py::GenEngineTest::test_inline_cb tornado/test/gen_test.py::GenEngineTest::test_ioloop_cb tornado/test/gen_test.py::GenEngineTest::test_key_mismatch tornado/test/gen_test.py::GenEngineTest::test_key_mismatch_tuple tornado/test/gen_test.py::GenEngineTest::test_key_reuse tornado/test/gen_test.py::GenEngineTest::test_key_reuse_tuple tornado/test/gen_test.py::GenEngineTest::test_leaked_callback tornado/test/gen_test.py::GenEngineTest::test_leaked_callback_tuple tornado/test/gen_test.py::GenEngineTest::test_multi tornado/test/gen_test.py::GenEngineTest::test_multi_dict tornado/test/gen_test.py::GenEngineTest::test_multi_dict_future tornado/test/gen_test.py::GenEngineTest::test_multi_empty tornado/test/gen_test.py::GenEngineTest::test_multi_exceptions tornado/test/gen_test.py::GenEngineTest::test_multi_future tornado/test/gen_test.py::GenEngineTest::test_multi_future_delayed tornado/test/gen_test.py::GenEngineTest::test_multi_future_dict_delayed tornado/test/gen_test.py::GenEngineTest::test_multi_future_duplicate tornado/test/gen_test.py::GenEngineTest::test_multi_future_exceptions tornado/test/gen_test.py::GenEngineTest::test_multi_mixed_types tornado/test/gen_test.py::GenEngineTest::test_multi_performance tornado/test/gen_test.py::GenEngineTest::test_multi_yieldpoint_delayed tornado/test/gen_test.py::GenEngineTest::test_multi_yieldpoint_dict_delayed tornado/test/gen_test.py::GenEngineTest::test_no_yield tornado/test/gen_test.py::GenEngineTest::test_orphaned_callback tornado/test/gen_test.py::GenEngineTest::test_parallel_callback tornado/test/gen_test.py::GenEngineTest::test_raise_after_stop tornado/test/gen_test.py::GenEngineTest::test_resume_after_exception_in_yield tornado/test/gen_test.py::GenEngineTest::test_return_value tornado/test/gen_test.py::GenEngineTest::test_return_value_tuple tornado/test/gen_test.py::GenEngineTest::test_reuse tornado/test/gen_test.py::GenEngineTest::test_stack_context_leak tornado/test/gen_test.py::GenEngineTest::test_stack_context_leak_exception tornado/test/gen_test.py::GenEngineTest::test_sync_raise_return tornado/test/gen_test.py::GenEngineTest::test_sync_raise_return_value tornado/test/gen_test.py::GenEngineTest::test_sync_raise_return_value_tuple tornado/test/gen_test.py::GenEngineTest::test_task tornado/test/gen_test.py::GenEngineTest::test_task_refcounting tornado/test/gen_test.py::GenEngineTest::test_task_transfer_stack_context tornado/test/gen_test.py::GenEngineTest::test_wait_all tornado/test/gen_test.py::GenEngineTest::test_wait_transfer_stack_context tornado/test/gen_test.py::GenEngineTest::test_with_arg tornado/test/gen_test.py::GenEngineTest::test_with_arg_tuple tornado/test/gen_test.py::GenCoroutineTest::test_async_await tornado/test/gen_test.py::GenCoroutineTest::test_async_await_mixed_multi_native_future tornado/test/gen_test.py::GenCoroutineTest::test_async_await_mixed_multi_native_yieldpoint tornado/test/gen_test.py::GenCoroutineTest::test_async_early_return tornado/test/gen_test.py::GenCoroutineTest::test_async_gen_return tornado/test/gen_test.py::GenCoroutineTest::test_async_raise tornado/test/gen_test.py::GenCoroutineTest::test_async_return tornado/test/gen_test.py::GenCoroutineTest::test_async_return_no_value tornado/test/gen_test.py::GenCoroutineTest::test_async_with_timeout tornado/test/gen_test.py::GenCoroutineTest::test_attributes tornado/test/gen_test.py::GenCoroutineTest::test_is_coroutine_function tornado/test/gen_test.py::GenCoroutineTest::test_moment tornado/test/gen_test.py::GenCoroutineTest::test_pass_callback tornado/test/gen_test.py::GenCoroutineTest::test_py3_leak_exception_context tornado/test/gen_test.py::GenCoroutineTest::test_replace_context_exception tornado/test/gen_test.py::GenCoroutineTest::test_replace_yieldpoint_exception tornado/test/gen_test.py::GenCoroutineTest::test_sleep tornado/test/gen_test.py::GenCoroutineTest::test_swallow_context_exception tornado/test/gen_test.py::GenCoroutineTest::test_swallow_yieldpoint_exception tornado/test/gen_test.py::GenCoroutineTest::test_sync_gen_return tornado/test/gen_test.py::GenCoroutineTest::test_sync_raise tornado/test/gen_test.py::GenCoroutineTest::test_sync_return tornado/test/gen_test.py::GenCoroutineTest::test_sync_return_no_value tornado/test/gen_test.py::GenWebTest::test_async_prepare_error_handler tornado/test/gen_test.py::GenWebTest::test_coroutine_exception_handler tornado/test/gen_test.py::GenWebTest::test_coroutine_sequence_handler tornado/test/gen_test.py::GenWebTest::test_coroutine_unfinished_sequence_handler tornado/test/gen_test.py::GenWebTest::test_exception_handler tornado/test/gen_test.py::GenWebTest::test_native_coroutine_handler tornado/test/gen_test.py::GenWebTest::test_sequence_handler tornado/test/gen_test.py::GenWebTest::test_task_handler tornado/test/gen_test.py::GenWebTest::test_undecorated_coroutines tornado/test/gen_test.py::GenWebTest::test_yield_exception_handler tornado/test/gen_test.py::WithTimeoutTest::test_already_resolved tornado/test/gen_test.py::WithTimeoutTest::test_completed_concurrent_future tornado/test/gen_test.py::WithTimeoutTest::test_completes_before_timeout tornado/test/gen_test.py::WithTimeoutTest::test_fails_before_timeout tornado/test/gen_test.py::WithTimeoutTest::test_timeout tornado/test/gen_test.py::WithTimeoutTest::test_timeout_concurrent_future tornado/test/gen_test.py::WaitIteratorTest::test_already_done tornado/test/gen_test.py::WaitIteratorTest::test_empty_iterator tornado/test/gen_test.py::WaitIteratorTest::test_iterator tornado/test/gen_test.py::WaitIteratorTest::test_iterator_async_await tornado/test/gen_test.py::WaitIteratorTest::test_no_ref tornado/test/gen_test.py::RunnerGCTest::test_gc
tornado/util.py tornado/concurrent.py tornado/http1connection.py tornado/gen.py
tornado/util.py tornado/concurrent.py tornado/http1connection.py tornado/gen.py