What is the meaning of the phrase "clean up after" and when and how to use it?

Solution 1:

From the Macmillan dictionary:

clean up after someone: to clean a place after someone has made it dirty or messy

Residents have been told to clean up after their dogs.

Another example (closer to the one in your question), desctructor functions in some programming languages let you remove from memory the variables that are no longer needed by the computer program, i.e. to perform a clean up when the program no longer needs to use an object.