[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] memory leaks with Py_BuildValue
- To: pygame-users@xxxxxxxx
- Subject: Re: [pygame] memory leaks with Py_BuildValue
- From: "Nirav Patel" <olpc@xxxxxxxxxxxxxx>
- Date: Wed, 3 Sep 2008 11:51:03 -0400
- Delivered-to: archiver@xxxxxxxx
- Delivered-to: pygame-users-outgoing@xxxxxxxx
- Delivered-to: pygame-users@xxxxxxxx
- Delivery-date: Wed, 03 Sep 2008 11:51:26 -0400
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:sender :to:subject:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references :x-google-sender-auth; bh=O3LeG2q+42dqpPA7v0eOu8o6Zxv0FSBl6o1wr+FNx3s=; b=vn/Lh2U4K7pHANKgXe/GoLi+gH6IhiS4tKpBEzM1CM35u6UC8Z+7Tq45+7vYKIgBil 1Yt4yKRMymr38UAHMDI0weVMqVD4KA7g8X/xG0aY/aJtsvKOUeV362nfWG0SjzggmAeb 29CIJF8SWDBEHjdbkkZh8tGPR6Dy90h02KCFA=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:sender:to:subject:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references:x-google-sender-auth; b=B3v3as7TpzsudF3JPyeIIO1M0ApLlrHIpkIjbBconPpPRNdnSEnFgX67WoK3Fzyq/T pIBHkcezqfmkTsGlgtb5M8eB5GAqjP7Yos/1ERAgS6OlUZKqFAiHcZ03bvjlm4nkHvZS 22QcdhWHMbot9Thn4SCkuwhjPOATBN4/kMVEg=
- In-reply-to: <7c1ab96d0809030813n2ecf8ae5qf3a346aef2a0430@xxxxxxxxxxxxxx>
- References: <7c1ab96d0809030813n2ecf8ae5qf3a346aef2a0430@xxxxxxxxxxxxxx>
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
Thanks,
I just committed a fix for it in mask.c.
Nirav
On Wed, Sep 3, 2008 at 11:13 AM, Campbell Barton <ideasman42@xxxxxxxxx> wrote:
> Hi, over a year ago I had a look at pygames py-c/api usage for memory
> leaks, and found a few, mainly with Py_BuildValue() using PyObjects
> which are incref'd,
> had another look at the recent SVN and found some more, not sure if
> they are new but they definitely cause memory leaks.
>
> For example - call pygame.mouse.get_cursor() in a loop of 10000 for
> every update in chimp.py and memory will go up 100's of meg fairly
> fast, patch below.
>
> you also might want to consider using PyTuple_Pack() which is faster
> but only in python 2.4 or later.
> http://docs.python.org/api/tupleObjects.html#l2h-583
>
>
> These leak too, much the same changes need to be made here also.
> ./src/mask.c:265: return Py_BuildValue ("(OO)", PyInt_FromLong(m10/m00),
> ./src/mask.c:268: return Py_BuildValue ("(OO)",
> PyInt_FromLong(0), PyInt_FromLong(0));
> ./src/mask.c:298: return Py_BuildValue ("O", PyFloat_FromDouble(theta));
> ./src/mask.c:300: return Py_BuildValue ("O", PyFloat_FromDouble(0));
>
>
> Index: src/mouse.c
> ===================================================================
> --- src/mouse.c (revision 1645)
> +++ src/mouse.c (working copy)
> @@ -171,7 +171,7 @@
> mouse_get_cursor (PyObject* self)
> {
> SDL_Cursor *cursor = NULL;
> - PyObject* xordata, *anddata;
> + PyObject* xordata, *anddata, *ret;
> int size, loop, w, h, spotx, spoty;
>
> VIDEO_INIT_CHECK ();
> @@ -201,8 +201,10 @@
> PyTuple_SET_ITEM (xordata, loop, PyInt_FromLong (cursor->data[loop]));
> PyTuple_SET_ITEM (anddata, loop, PyInt_FromLong (cursor->mask[loop]));
> }
> -
> - return Py_BuildValue ("((ii)(ii)OO)", w, h, spotx, spoty,
> xordata, anddata);
> + ret = Py_BuildValue ("((ii)(ii)OO)", w, h, spotx, spoty, xordata, anddata);
> + Py_DECREF (xordata);
> + Py_DECREF (anddata);
> + return ret;
> }
>
> static PyMethodDef mouse_builtins[] =
>