Closed mknkmyzk closed 1 year ago
Thank you for merging my memory leak patch. However, there remains one more memory leak with numpy. e.g.
require 'pycall/import' include PyCall::Import pyimport :gc # require 'numpy' # np = Numpy pyimport :numpy, as: :np zzz = np.zeros(1000000) 10000.times{ zzz[zzz == 255] = 0 # mem leak !! zzz > 100 # mem leak !! gc.collect() GC.start }
The following is my tentative patch:
--- pycall.c.ORG 2023-08-25 12:33:56.702026311 +0900 +++ pycall.c.NEW 2023-08-25 12:57:10.719879875 +0900 @@ -793,7 +793,10 @@ pycall_libpython_helpers_m_compare(VALUE pycall_pyerror_fetch_and_raise("PyObject_RichCompare in pycall_libpython_helpers_m_compare"); } - return pycall_pyobject_to_ruby(res); + // return pycall_pyobject_to_ruby(res); + VALUE obj = pycall_pyobject_to_ruby(res); + pycall_Py_DecRef(res); // ADDED *** for numpy (e.g. np.array([1,2,3]) < 1) + return obj; } static int is_pyobject_wrapper(VALUE obj);
@mknkmyzk Thank you for your report. Could you make this patch a pull-request?
Thank you for merging my memory leak patch. However, there remains one more memory leak with numpy. e.g.
The following is my tentative patch: