Freeing memory space after returning aggregation