Re: plpythonu memory leak - Mailing list pgsql-general

From Daniel Popowich
Subject Re: plpythonu memory leak
Date
Msg-id 19765.42463.580394.669919@io.astro.umass.edu
Whole thread Raw
In response to Re: plpythonu memory leak  (Alex Hunsaker <badalex@gmail.com>)
Responses Re: plpythonu memory leak  (Daniel Popowich <danielpopowich@gmail.com>)
List pgsql-general
Alex Hunsaker writes:
> FYI if I don't use a slice copy here I can't get it to leak. ( find my
> test case at the end ) I don't know enough about python to know if
> thats a pl/python issue or python doing what its told--  having never
> really wrote any python myself.
>
> ---------------
> -- leaks big time
> CREATE  or replace FUNCTION pygaps_leak() RETURNS void
>    LANGUAGE plpythonu
>    AS $$
> results = plpy.execute("""select generate_series(0, 1000000)""")
> prev = results[0]
> for curr in results[1:]:
>   prev = curr
> return
> $$;
>
> -- does not leak
> CREATE  or replace FUNCTION pygaps_no_leak() RETURNS void
>    LANGUAGE plpythonu
>    AS $$
> results = plpy.execute("""select generate_series(0, 1000000)""")
> prev = results[0]
> for curr in range(1, len(results)):
>   prev = curr
> return
> $$;

Alex,

Great find!  Yes, it's definitely leaking when taking a slice.
Something is hanging on to the reference to the slice object and/or
the reference count is not properly managed: I modified your "leak"
function and added explicit calls to the python garbage collector with
no result.

I'll hunt around in the source for the leak.  Regardless of my
findings, I'll submit a bug.

Thanks!

Dan Popowich


pgsql-general by date:

Previous
From: Xiaobo Gu
Date:
Subject: postgresql-9.0.2-1-windows_x64 from EnterpriseDB can't install on Win 7 home basic 64 bit
Next
From: Xiaobo Gu
Date:
Subject: Re: postgresql-9.0.2-1-windows_x64 from EnterpriseDB can't install on Win 7 home basic 64 bit