implemented end_memory