Bill Allombert on Tue, 19 Oct 2021 20:46:58 +0200


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

Re: memory leak on concatenating two lists


Le Tue, Oct 19, 2021 at 09:46:58AM -0400, Max Alekseyev a écrit :
> 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?

This should be fixed in master (d43896622).
You can work around it by doing 
  L = concat(L,Vec(temp));
or similar ways to avoid concatening two lists.

Thanks for detecting this issue!
Bill