countUp.js icon indicating copy to clipboard operation
countUp.js copied to clipboard

Cleanup / Destroy

Open somegooser opened this issue 2 years ago • 5 comments

Is there any way to destory / cleanup countup after use?

Thanks!

somegooser avatar Nov 25 '22 10:11 somegooser

you can simply delete it:

const countUp = new CountUp('targetId', 5234);
countUp.start();

and later

delete countUp;

inorganik avatar Nov 25 '22 15:11 inorganik

Thank you for the comment but will this also delete events attached via enableScrollSpy?

somegooser avatar Nov 25 '22 16:11 somegooser

good point. You could do

delete window['onScrollFns'];
window.onscroll = null;

I really don't think you're going to get any performance wins by doing that.

inorganik avatar Nov 25 '22 16:11 inorganik

However if you deleted your countUp instance, and it was using scroll spy, you could get a null pointer exception, so I could add a detach method.

inorganik avatar Nov 25 '22 16:11 inorganik

This is published in v2.4.2

inorganik avatar Jan 28 '23 17:01 inorganik