Frees memory after deleting objects