Python plugins leak memory
Submitted by Karl
Link to original bug (#646353)
Description
Created attachment 184793 Python script for plugin
Certain Python plugins cause memory leaks. I am not certain whether ALL Python plugins cause leaks, or just specific actions taken by them. I was able to reproduce one:
-
mkdir $HOME/.gnumeric/1.10.13/plugins/test (from now on, plugindir=$HOME/.gnumeric/1.10.13/plugins/test)
-
Create $plugindir/plugin.xml with the following contents:
<plugin id="Gnumeric_test">
<information>
<name>
test</name>
<description>
test</description>
</information>
</loader>
<services>
<service type="function_group" id="test">
<category>
Local Python</category>
<functions>
</functions>
</service>
</services>
</plugin>
-
Create $plugindir/test.py with the following contents: import Gnumeric def mypoly (a, coeffs) : value = 0 nrows = int(Gnumeric.functions'rows') for n in range(nrows) : value += Gnumeric.functions['product'](a**n, Gnumeric.functions'index') return value test_functions = { 'MYPOLY' : mypoly }
-
Create a spreadsheet that contains the numbers 1-10 in cells A1:A10, and the squares of those numbers (1, 4, 9, 16, etc.) in cells B1:B10. Enter 1 for the value in cells B15:B20. Now enter the formula '=mypoly(A1,$B
15:
B$20)' in cell C1 and fill down to cell C10. Enter '=(b1-c1)^2' as cell D2 and fill down. Now enter cell D13 as '=sum(d1:d10)'. -
Open Solver. Set Target Cell -> D13; to Min; By Changing Cells -> B15:B20. Choose a non-linear model, no assumption of non-negativity, use NSolve.
-
Click "Solve" button. Memory allocated (in system monitor, for example) will increase, slowly, as more and more calls to MYPOLY() are evaluated.
-
Close Gnumeric. Memory is freed.
The steps involving solver are unnecessary---the leak is evident for any sheet that involves enough evaluations of the Python plugin. For example, I can create a sheet with a bunch of calls to mypoly in different cells and just hit F9 (evaluate cells) over and over again and I'll eventually get the leak---it just takes a lot longer that way because I don't have Solver auto-evaluating things for me. (The solution to the above Solve block is trivial, of course; set cell B17 to 1 and everything else to 0; but Solver doesn't know that, so it will actually look for a solution for quite a while, which makes this an effective test).
For sheets with more cells and/or more Solver iterations using plugins similar to the above, the leak is severe enough that I must restart Gnumeric after every Solver run to deallocate the leaked memory.
Other info: Gnumeric 1.10.13 built for Fedora 13 (build from repository). Kernel 2.6.34.8-68.fc13.x86_64.
Attachment 184793, "Python script for plugin":
test.py
Version: 1.10.x