Python 3.5.1 C API, the global available available is not destroyed when delete the module

dieter dieter at handshake.de
Thu Sep 22 02:10:44 EDT 2016


dl l <ldlchina at gmail.com> writes:
> I understood call PyGC_collect to release object cycles. But in my python
> test code, seems there is NO reference cycle on the Simple object in the
> python test code. Why needs to call PyGC_Collect() here?
>
> =========================================================
>
> class Simple:
>      def __init__( self ):
>          print('Simple__init__')
>      def __del__( self ):
>          print('Simple__del__')
>
> simple = None
>
> def run():
>     global simple
>     simple = Simple()
>
> if __name__ == '__main__':
> 	run()

I do not see a cycle in this example. Thus, maybe, Python itself
has introduced one (maybe via "__builtins__").

To further analyse the case, I would start by checking the "gc" module's
documentation to find out, whether it provides a way to get information
about the cycles it has found (and would have deleted if it had
not generated references for this analysis).




More information about the Python-list mailing list