Replace ArrayList with Set, find memory leak