xref: /third_party/python/Lib/test/leakers/README.txt (revision 7db96d56)
17db96d56Sopenharmony_ciThis directory contains test cases that are known to leak references.
27db96d56Sopenharmony_ciThe idea is that you can import these modules while in the interpreter
37db96d56Sopenharmony_ciand call the leak function repeatedly.  This will only be helpful if
47db96d56Sopenharmony_cithe interpreter was built in debug mode.  If the total ref count
57db96d56Sopenharmony_cidoesn't increase, the bug has been fixed and the file should be removed
67db96d56Sopenharmony_cifrom the repository.
77db96d56Sopenharmony_ci
87db96d56Sopenharmony_ciNote:  be careful to check for cyclic garbage.  Sometimes it may be helpful
97db96d56Sopenharmony_cito define the leak function like:
107db96d56Sopenharmony_ci
117db96d56Sopenharmony_cidef leak():
127db96d56Sopenharmony_ci    def inner_leak():
137db96d56Sopenharmony_ci        # this is the function that leaks, but also creates cycles
147db96d56Sopenharmony_ci    inner_leak()
157db96d56Sopenharmony_ci    gc.collect() ; gc.collect() ; gc.collect()
167db96d56Sopenharmony_ci
177db96d56Sopenharmony_ciHere's an example interpreter session for test_gestalt which still leaks:
187db96d56Sopenharmony_ci
197db96d56Sopenharmony_ci>>> from test.leakers.test_gestalt import leak
207db96d56Sopenharmony_ci[24275 refs]
217db96d56Sopenharmony_ci>>> leak()
227db96d56Sopenharmony_ci[28936 refs]
237db96d56Sopenharmony_ci>>> leak()
247db96d56Sopenharmony_ci[28938 refs]
257db96d56Sopenharmony_ci>>> leak()
267db96d56Sopenharmony_ci[28940 refs]
277db96d56Sopenharmony_ci>>> 
287db96d56Sopenharmony_ci
297db96d56Sopenharmony_ciOnce the leak is fixed, the test case should be moved into an appropriate
307db96d56Sopenharmony_citest (even if it was originally from the test suite).  This ensures the
317db96d56Sopenharmony_ciregression doesn't happen again.  And if it does, it should be easier
327db96d56Sopenharmony_cito track down.
33