0

导入 uuid 时发现内存泄漏。

Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import gc
>>> gc.set_debug(gc.DEBUG_LEAK)
>>> gc.collect()
0
>>> gc.garbage
[]
>>> import uuid
>>> gc.collect()
gc: collectable <tuple 026A2D30>
gc: collectable <_ctypes.PyCSimpleType 026DC190>
gc: collectable <getset_descriptor 026A4FA8>
gc: collectable <getset_descriptor 026A4FD0>
gc: collectable <tuple 026A5600>
gc: collectable <StgDict 026A61E0>
gc: collectable <tuple 026A84B0>
gc: collectable <StgDict 026AA7C8>
gc: collectable <_ctypes.PyCArrayType 026FAD30>
gc: collectable <getset_descriptor 026AD148>
gc: collectable <getset_descriptor 026AD170>
gc: collectable <tuple 026AC150>
gc: collectable <tuple 0269BA50>
gc: collectable <StgDict 026AA978>
gc: collectable <_ctypes.PyCFuncPtrType 026FB4D0>
gc: collectable <getset_descriptor 02699D50>
gc: collectable <getset_descriptor 02699E18>
gc: collectable <tuple 0269D180>
gc: collectable <tuple 0269BBF0>
gc: collectable <StgDict 026AAA50>
gc: collectable <_ctypes.PyCFuncPtrType 026FB6B8>
gc: collectable <getset_descriptor 026AD5D0>
gc: collectable <getset_descriptor 026AD5F8>
gc: collectable <tuple 0269D540>
25
**>>> gc.garbage**
[(<type '_ctypes._SimpleCData'>,), <class 'ctypes.c_longdouble'>, <attribute '__dict__' of 'c_longdouble' objects>, <attribute '__weakref__' of 'c_longdouble' objects>
ypes.c_longdouble'>, <type '_ctypes._SimpleCData'>, <type '_ctypes._CData'>, <type 'object'>), {'__dict__': <attribute '__dict__' of 'c_longdouble' objects>, '_type_':
le__': 'ctypes', '__weakref__': <attribute '__weakref__' of 'c_longdouble' objects>, '__doc__': None}, (<type '_ctypes.Array'>,), {'__module__': 'ctypes._endian', '__d
ibute '__dict__' of 'c_long_Array_3' objects>, '__weakref__': <attribute '__weakref__' of 'c_long_Array_3' objects>, '_length_': 3, '_type_': <class 'ctypes.c_long'>,
ne}, <class 'ctypes._endian.c_long_Array_3'>, <attribute '__dict__' of 'c_long_Array_3' objects>, <attribute '__weakref__' of 'c_long_Array_3' objects>, (<class 'ctype
ong_Array_3'>, <type '_ctypes.Array'>, <type '_ctypes._CData'>, <type 'object'>), (<type '_ctypes.PyCFuncPtr'>,), {'__module__': 'ctypes', '__dict__': <attribute '__di
ncPtr' objects>, '__weakref__': <attribute '__weakref__' of '_FuncPtr' objects>, '_flags_': 1, '__doc__': None, '_restype_': <class 'ctypes.c_long'>}, <class 'ctypes._
ttribute '__dict__' of '_FuncPtr' objects>, <attribute '__weakref__' of '_FuncPtr' objects>, (<class 'ctypes._FuncPtr'>, <type '_ctypes.PyCFuncPtr'>, <type '_ctypes._C
 'object'>), (<type '_ctypes.PyCFuncPtr'>,), {'__module__': 'ctypes', '__dict__': <attribute '__dict__' of '_FuncPtr' objects>, '__weakref__': <attribute '__weakref__'
' objects>, '_flags_': 1, '__doc__': None, '_restype_': <class 'ctypes.c_long'>}, <class 'ctypes._FuncPtr'>, <attribute '__dict__' of '_FuncPtr' objects>, <attribute '
of '_FuncPtr' objects>, (<class 'ctypes._FuncPtr'>, <type '_ctypes.PyCFuncPtr'>, <type '_ctypes._CData'>, <type 'object'>)]
**>>> len(gc.garbage)**
24
>>>

搜索相关资源后,我发现导入 ctypes 的问题相同。我在http://bugs.python.org/issue12142发现了这个问题。

我想知道这是否也是我应该向 bugs.python.org 报告的错误。

4

1 回答 1

1

不是泄漏。设置gc.DEBUG_LEAK会导致垃圾收集器将甚至可收集的对象附加到垃圾列表而不是释放它们。您可以看到收集器发现的所有内容都是免费的,因为所有消息都说collectable.

于 2013-07-11T16:00:01.393 回答