Message384654
> encodings._cache['cp932'] = _codecs_jp.getcodec('cp932')
* encodings._cache is kept alive by encodings.search_function.__globals__
* encodings.search_function function is kept alive by PyInterpreterState.codec_search_path list. The function by _PyCodec_Register() in encodings/__init__.py: codecs.register(search_function).
For example, unregistering the search function prevents the leak:
import encodings
import _codecs_jp
encodings._cache['cp932'] = _codecs_jp.getcodec('cp932')
import codecs
codecs.unregister(encodings.search_function)
The PyInterpreterState.codec_search_path list is cleared at Python exit by interpreter_clear().
The weird part is that the _codecs_jp.getcodec('cp932') codec object *is* deleted. I checked and multibytecodec_dealloc() is called with the object stored in the encodings cache.
A _multibytecodec.MultibyteCodec instance (MultibyteCodecObject* structure in C) is a simple type: it only stores pointer to C functions and C strings. It doesn't contain any Python object. So I don't see how it could be part of a reference cycle by itself. Moreover, again, it is deleted. |
|
Date |
User |
Action |
Args |
2021-01-08 12:23:51 | vstinner | set | recipients:
+ vstinner, corona10, erlendaasland |
2021-01-08 12:23:51 | vstinner | set | messageid: <1610108631.55.0.0877328017147.issue42866@roundup.psfhosted.org> |
2021-01-08 12:23:51 | vstinner | link | issue42866 messages |
2021-01-08 12:23:51 | vstinner | create | |
|