Alexander Shumakovitch on Sat, 24 Aug 2002 20:56:56 +0200 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Heap memory leak in Pari/GP 2.1.4 during vector operations. |
This is my first post to the list, so I would like to start by thanking everybody involved for this wonderful program! Now back to business ;-) I'm doing some computation using Pari which involve, in particular, calling one function many (hundreds) times with different arguments. The function in question assigns some values to global variables, but doesn't increase their sizes dramatically. Nonetheless, I've noticed (using 'top') a huge increase in the memory usage with each run of the function (like 20M per run). getheap() also shows an increase in occupied blocks. Pari segfaults after just dozens of calls to the functions and I have to intervene manually every time to restart the computations. This is the background. After some tries, I've managed to trace down the problem to initializations of vectors (or matrices) whose entries are going to be vectors as well. I used to do it in one operator. But in this case assignment of arbitrary values to elements of those vectors grabs some blocks on heap, which are not freed even after doing kill(). Here is how to trigger the bug: (20:35) gp > v=vector(2,i,vector(i));v[2][1]=5;getheap time = 0 ms. %2 = [34, 225] (20:35) gp > v=vector(2,i,vector(i));v[2][1]=5;getheap time = 0 ms. %3 = [35, 232] (20:35) gp > v=vector(2,i,vector(i));v[2][1]=5;getheap time = 0 ms. %4 = [36, 239] I have histsize set to 1, so the growth of the history array is not an issue. Apparently, one more block is being allocated every time without being freed later. An equivalent (in my view, at least) construction works just fine: (20:35) gp > v=vector(2);v[1]=vector(1);v[2]=vector(2);v[2][1]=5;getheap time = 0 ms. %5 = [39, 266] (20:39) gp > v=vector(2);v[1]=vector(1);v[2]=vector(2);v[2][1]=5;getheap time = 0 ms. %6 = [39, 266] And here is a similar bug with column assignments: (20:43) gp > x=vector(2)~; time = 0 ms. (20:43) gp > m=matrix(2,2);m[,2]=x;getheap time = 0 ms. %2 = [35, 240] (20:43) gp > m=matrix(2,2);m[,2]=x;getheap time = 0 ms. %3 = [36, 253] (20:43) gp > m=matrix(2,2);m[,2]=x;getheap time = 0 ms. %4 = [37, 264] No problem with rows though: (20:43) gp > y=vector(2); time = 0 ms. (20:44) gp > m=matrix(2,2);m[2,]=y;getheap time = 0 ms. %7 = [40, 287] (20:44) gp > m=matrix(2,2);m[2,]=y;getheap time = 0 ms. %8 = [40, 287] That's all at the moment ;-) Thanks in advance! --- Alexander.