When do you call the cleanup method?

When a Bolt is shut down, the cleanup method is called, and it should clear up any resources that were opened. On the cluster, there’s no certainty that this procedure will be called: For example, if the computer on which the job is executing crashes, there is no way to call the function.

When you run topologies in local mode (with a Storm cluster simulated in the background), and you want to be able to run and stop many topologies without experiencing resource leaks, you should use the cleaning technique.