You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pylucene-dev@lucene.apache.org by Aric Coady <ar...@gmail.com> on 2009/07/30 21:18:46 UTC

memory leak in string array

Hey,

Looks like there are some memory leaks in JArray_string, when  
iterating or accessing its items.  I've seen it reproduce with 2.4.1  
on linux and osx.  Attached is a test case to demonstrate it using  
Document.getValues, and a potential patch.


Re: memory leak in string array

Posted by Andi Vajda <va...@apache.org>.
On Thu, 30 Jul 2009, Aric Coady wrote:

> On Jul 30, 2009, at 3:18 PM, Andi Vajda wrote:
>> On Thu, 30 Jul 2009, Aric Coady wrote:
>>> Looks like there are some memory leaks in JArray_string, when iterating or 
>>> accessing its items.  I've seen it reproduce with 2.4.1 on linux and osx. 
>>> Attached is a test case to demonstrate it using Document.getValues, and a 
>>> potential patch.
>> 
>> Arik,
>> 
>> I got your test case but the patch seems to be missing ?
>
> Oh, here it is inlined.  Looks like the same problem as described in 
> http://lists.osafoundation.org/pipermail/pylucene-dev/2008-October/002939.html.

Thanks, I applied your patch in rev 800403.

Andi..

>
> Index: jcc/sources/JArray.h
> ===================================================================
> --- jcc/sources/JArray.h	(revision 799400)
> +++ jcc/sources/JArray.h	(working copy)
> @@ -295,6 +295,7 @@
>            jstring value = (jstring)
>                env->getObjectArrayElement((jobjectArray) this$, i);
>            PyObject *obj = env->fromJString(value);
> +            env->get_vm_env()->DeleteLocalRef(value);
>
>            PyList_SET_ITEM(list, i - lo, obj);
>        }
> @@ -314,7 +315,9 @@
>                jstring str = (jstring)
>                    env->getObjectArrayElement((jobjectArray) this$, n);
>
> -                return env->fromJString(str);
> +                PyObject *obj = env->fromJString(str);
> +                env->get_vm_env()->DeleteLocalRef(str);
> +                return obj;
>            }
>        }

Re: memory leak in string array

Posted by Andi Vajda <va...@apache.org>.
On Thu, 30 Jul 2009, Aric Coady wrote:

> On Jul 30, 2009, at 3:18 PM, Andi Vajda wrote:
>> On Thu, 30 Jul 2009, Aric Coady wrote:
>>> Looks like there are some memory leaks in JArray_string, when iterating or 
>>> accessing its items.  I've seen it reproduce with 2.4.1 on linux and osx. 
>>> Attached is a test case to demonstrate it using Document.getValues, and a 
>>> potential patch.
>> 
>> Arik,
>> 
>> I got your test case but the patch seems to be missing ?
>
> Oh, here it is inlined.  Looks like the same problem as described in 
> http://lists.osafoundation.org/pipermail/pylucene-dev/2008-October/002939.html.

Thanks, indeed that looks familiar.

Andi..

>
> Index: jcc/sources/JArray.h
> ===================================================================
> --- jcc/sources/JArray.h	(revision 799400)
> +++ jcc/sources/JArray.h	(working copy)
> @@ -295,6 +295,7 @@
>            jstring value = (jstring)
>                env->getObjectArrayElement((jobjectArray) this$, i);
>            PyObject *obj = env->fromJString(value);
> +            env->get_vm_env()->DeleteLocalRef(value);
>
>            PyList_SET_ITEM(list, i - lo, obj);
>        }
> @@ -314,7 +315,9 @@
>                jstring str = (jstring)
>                    env->getObjectArrayElement((jobjectArray) this$, n);
>
> -                return env->fromJString(str);
> +                PyObject *obj = env->fromJString(str);
> +                env->get_vm_env()->DeleteLocalRef(str);
> +                return obj;
>            }
>        }

Re: memory leak in string array

Posted by Aric Coady <ar...@gmail.com>.
On Jul 30, 2009, at 3:18 PM, Andi Vajda wrote:
> On Thu, 30 Jul 2009, Aric Coady wrote:
>> Looks like there are some memory leaks in JArray_string, when  
>> iterating or accessing its items.  I've seen it reproduce with  
>> 2.4.1 on linux and osx. Attached is a test case to demonstrate it  
>> using Document.getValues, and a potential patch.
>
> Arik,
>
> I got your test case but the patch seems to be missing ?

Oh, here it is inlined.  Looks like the same problem as described in http://lists.osafoundation.org/pipermail/pylucene-dev/2008-October/002939.html 
.

Index: jcc/sources/JArray.h
===================================================================
--- jcc/sources/JArray.h	(revision 799400)
+++ jcc/sources/JArray.h	(working copy)
@@ -295,6 +295,7 @@
              jstring value = (jstring)
                  env->getObjectArrayElement((jobjectArray) this$, i);
              PyObject *obj = env->fromJString(value);
+            env->get_vm_env()->DeleteLocalRef(value);

              PyList_SET_ITEM(list, i - lo, obj);
          }
@@ -314,7 +315,9 @@
                  jstring str = (jstring)
                      env->getObjectArrayElement((jobjectArray) this$,  
n);

-                return env->fromJString(str);
+                PyObject *obj = env->fromJString(str);
+                env->get_vm_env()->DeleteLocalRef(str);
+                return obj;
              }
          }


Re: memory leak in string array

Posted by Andi Vajda <va...@apache.org>.
On Thu, 30 Jul 2009, Aric Coady wrote:

> Looks like there are some memory leaks in JArray_string, when iterating or 
> accessing its items.  I've seen it reproduce with 2.4.1 on linux and osx. 
> Attached is a test case to demonstrate it using Document.getValues, and a 
> potential patch.

  Arik,

I got your test case but the patch seems to be missing ?

Andi..