Max Alekseyev on Tue, 19 Oct 2021 15:47:38 +0200


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

memory leak on concatenating two lists


The following code illustrates the problem:

L = List();
while(1,
   my( temp = List(vector(100,i,i)) );
   L = concat(L,temp);
   for(i=1,100, listpop(L));
   print1(getheap(),"    ",Strchr(13));
);
}

While list L remains empty at the end of each while-loop iteration, the memory consumption grows indefinitely.
If I replace "L = concat(L,temp);" with, say,
for(i=1,#temp, listput(L,temp[i]));
then memory consumption remains constant. However, this does not look like an efficient way to concatenate lists.
Can concat() be fixed, or what would be an efficient and memory-safe approach here?

Regards.
Max