niner / inline-python-pm

Inline::Python - Write Perl subs and classes in Python.
https://metacpan.org/release/Inline-Python
20 stars 13 forks source link

Fix dictionary with `unicode` keys memory leak #13

Closed pypt closed 7 years ago

pypt commented 7 years ago

Fixes #12.

f131c62 is the actual fix, more of a wild intuitive guess than a thorough investigation. 4e48791 tests the fix by fetching a Python dictionary for 5m times and having a look at the RSS memory usage afterwards.

niner commented 7 years ago

Thanks for looking into this! I have tried, but to my shame, I've just not yet succeeded in installing Inline::Python with Python 3.5 as the openSUSE Python packages miss the symlink to the libpython.so in /usr/lib64/python3.5/config-3.5m/ I really need to modernize the whole configuration code and use python-config instead.

Anyway, from your fix, I infer that the same leak should also be present with Python 2.7 when the dict contains a u'Unicode string' as a key. It's just that on Python 3 all strings are Unicode strings, so PyUnicode_Check succeeds much more often. And indeed, that's exactly how I can reproduce it here!

pypt commented 7 years ago

Thanks for responding so quickly!

You're right, leak happens when dictionary with u'Unicode keys' gets returned from Python to Perl.

Would you be able to quickly release an updated version to CPAN?

niner commented 7 years ago

Inline::Python 0.51 is on its way to the CPAN mirrors :) I just softened the dependency on Proc::ProcessTable and Test::Deep to ensure a smooth installation.