In some cases TopN will use excessive memory. E.g. if you have a large number of input rows containing strings sorted in reverse order, it will allocate memory for all of the strings and never free it.
We should either recycle the allocations or periodically re-materialise and garbage collect the old allocations
There is a TODO in the code already.