davatron5000 / FitText.js

A jQuery plugin for inflating web type
http://fittextjs.com
6.76k stars 1.39k forks source link

Memory leak when repeatedly calling `fitText()` #177

Closed Joebu closed 6 months ago

Joebu commented 6 months ago

Repeatedly calling fitText is creating a memory leak I call it each time I load data since it is always a different amount of elements. I was observing an increase in memory on each call. till it boiled down to the fitText call, since in each call its subscribing to an event and never unsubscribes this line

   // Call on resize. Opera debounces their resize by default.
   $(window).on('resize.fittext orientationchange.fittext', resizer);
davatron5000 commented 6 months ago

That's somewhat based on how you're loading elements. There's a few options...

  1. When you destroy/replace elements call $(window).off('resize.fittext orientationchange.fittext)
  2. Modify to create your own destroy() method
  3. Don't use FitText - CSS has evolved to the point you likely don't need fitText and can just use font-size: clamp( 1rem, 10vw, 3rem) (replacing your own min/max values there).
Joebu commented 6 months ago

Thanks. (I'm not that css expert )