Call destroy method on page change


I am working on a plugin, which uses the timeout function to call a method every second. the method has a Ajax call. The problem is when I navigate to a different dashboard or a page, still the timeout function is calling the Ajax request.

How to stop the timeout function, when the plugin is not displayed in the page.