change freeIds to stack to prevent excessive buffer growth