I don't know how you do event handling (maybe you could share some code), so I will assume you are using standard HTML event handling.
const target = document.querySelector('canvas')const handler = function() { /* ... */ }target.addEventHandler('event-name', handler)target.removeEventHandler('event-name', handler) (docs)You should make it a habit to clean up everything after use, the latest on shutdown of your main code, especially if you do not stop the program, as in your case.
Ankur Singh
Software Developer