From: SourceForge.net <no...@so...> - 2011-04-26 23:32:54
|
Bugs item #1501284, was opened at 2006-06-05 15:27 Message generated for change (Comment added) made by sswamida You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=101645&aid=1501284&group_id=1645 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: python Group: None Status: Open Resolution: Accepted Priority: 5 Private: No Submitted By: S Joshua Swamidass (sswamida) Assigned to: szager (szager) Summary: OUPUT typemap --> python memory leak Initial Comment: using the output typemap with Swig 1.3.24, Python 2.4 on Linux causes a memory leak. For example, consider a swig declaration: void func(double *OUTPUT, double *OUTPUT); for the following C function: void func(double *out1,double *out2) { *out1=1324; *out2=24; } This function ca be used as expected: >>> from swigmodule import func >>> func() (1324.0, 24.0) However it produces a memory leak revealed by watching memory usage with repeated iteration: >>> while True: ... func() -----> rapidly increased memory usage. Please advise. ---------------------------------------------------------------------- Comment By: S Joshua Swamidass (sswamida) Date: 2011-04-26 16:32 Message: So, I think you can safely close this bug. It seems to be fixed in the current swig version. That's godo news. Sorry about the bother, this bug report is from about 5 years ago. ---------------------------------------------------------------------- Comment By: S Joshua Swamidass (sswamida) Date: 2011-04-25 22:27 Message: Oh I see there is a new version. Let me try it out and get back to you. ---------------------------------------------------------------------- Comment By: szager (szager) Date: 2011-04-25 22:17 Message: I should clarify that the typemap in my previous comment is also the default OUTPUT typemap. ---------------------------------------------------------------------- Comment By: szager (szager) Date: 2011-04-25 22:02 Message: OK, I'm reopening this bug, but I need some more info from you. You mention a typemap, but you don't have any in your example. I assumed that you were using these typemaps from the SWIG python documentation: %typemap(argout) double * { PyObject *o, *o2, *o3; o = PyFloat_FromDouble(*$1); if ((!$result) || ($result == Py_None)) { $result = o; } else { if (!PyTuple_Check($result)) { PyObject *o2 = $result; $result = PyTuple_New(1); PyTuple_SetItem(target,0,o2); } o3 = PyTuple_New(1); PyTuple_SetItem(o3,0,o); o2 = $result; $result = PySequence_Concat(o2,o3); Py_DECREF(o2); Py_DECREF(o3); } } %typemap(in,numinputs=0) double * (double temp) { $1 = &temp; } Using those typemaps with the SVN-latest SWIG and python2.7, I can't reproduce your problem. I run with the 'while True' loop, and the process memory usage stays flat. Can you confirm that you're using the above typemaps? If so, can you try with a more recent version of SWIG and see if it helps? Stefan ---------------------------------------------------------------------- Comment By: S Joshua Swamidass (sswamida) Date: 2011-04-25 16:30 Message: One more quick point. If you swig the code I put up there, and run while True: func() Then this will increase memory to the point of causing a seg fault. ---------------------------------------------------------------------- Comment By: S Joshua Swamidass (sswamida) Date: 2011-04-25 16:28 Message: Hello szager, This is not a problem with python. Your code is not memory efficient. A better version: for i in xrange(10000000): i + 1 Range generates the full list first in memory before performing the iteration. Xrange does not and uses constant memory. This is clearly a bug in the swig template. The workaround is to add in code to free out1 and out2 our avoid the template altogether. But this is clearly a memory leak error in swig's template. ---------------------------------------------------------------------- Comment By: szager (szager) Date: 2011-04-25 15:55 Message: I believe this is a characteristic of python, not SWIG. When I run this code: for i in range(10000000): i + 1 ... I get the essentially the same memory profile as with your example. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=101645&aid=1501284&group_id=1645 |