question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

memory leak, DOM nodes

See original GitHub issue

https://codepen.io/wyzix33/pen/aeaMJx

Your Environment

  • flatpickr version used:4.6.2

  • Browser name and version: Chrome Version 76.0.3809.100 (Official Build) (64-bit)

  • OS and version: Windows 10

I’m detecting a Memory leak when creating and destroying flatpickr, Please test with that pen, just press add, click the input to see the calendar and click remove to destroy it, repeat … This is what i’m getting: flatpickrMemLeak

Thanks

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:5
  • Comments:12 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
chmlncommented, May 5, 2021

Hey guys,

This seems to have become an issue again recently. It’s happened before and is definitely solvable. I’ll investigate what’s causing the leak and push out a fix.

Will keep you all posted 😃

3reactions
Nicolasclearleafcommented, Aug 15, 2019

+1 flatpickr version used:4.6.2 Chrome Version 76.0.3809.100 (Official Build) (64-bit) MacOS Mojave v10.14.6 (18G87)

I try to destroy flatpickr instance to reuse the input (last version 4.6.2) but this seem always exist in the DOM. and this create some conflicts for the init date also in the library : first initialization work fine but the next is wrong, on the second for example, init nodes is equal to

(14) [input.form-control.timepicker.flatpickr-input, input.form-control.timepicker.flatpickr-input, input.form-control.timepicker.flatpickr-input, input.form-control.timepicker.flatpickr-input, input.form-control.timepicker.flatpickr-input, input.form-control.timepicker.flatpickr-input, input.form-control.timepicker.flatpickr-input, input.form-control.timepicker.flatpickr-input, input.form-control.timepicker.flatpickr-input, input.form-control.timepicker.flatpickr-input, input.form-control.timepicker.flatpickr-input, input.form-control.timepicker.flatpickr-input, input.form-control.timepicker.flatpickr-input, input.form-control.timepicker.flatpickr-input]

If I “console.log(self)” at the end of destroy() function, self is always with a flatpickr instance and input freshly set with a new flatpickr instance have a good value first and if click on the input, this set a default now() value.

I create my instances with this:

const config = {
  enableTime: true,
  noCalendar: true,
  dateFormat: "G:i K",
  minuteIncrement: 1,
  allowInput: true,
  defaultDate: null,
  disableMobile: false, // can be true to desactive the native picker on mobile
};
this.timePickerInst = flatpickr('.timepicker', config);

I can detroy() with this but if I reuse an input, normally flatpickr do the same in background, If I use this function in addition, in my console I destroy 2 times the instances but this seem to be nothing effective

timePickerDestroy(callback) {
  // destroy timepicker instances
  for (var i = this.timePickerInst.length - 1; i >= 0; i--) {
    this.timePickerInst[i].destroy(); // destroy the timepicker instance
    delete this.timePickerInst[i]; // no useful
  }
  callback && callback();
},
Read more comments on GitHub >

github_iconTop Results From Across the Web

Debug DOM memory leaks with the Detached Elements tool
A memory leak can occur in your application when an element is no longer attached to the Document Object Model (DOM) tree, ...
Read more >
Debug memory leaks with the Microsoft Edge Detached ...
A DOM memory leak occurs when an application keeps references to more and more of these detached elements, without actually reusing them ...
Read more >
Causes of Memory Leaks in JavaScript and How to Avoid Them
Common Sources of Memory Leaks in JavaScript Code # · 1. Accidental global variables · 2. Closures · 3. Timers · 4. Event...
Read more >
Get detached DOM elements to investigate memory leaks
Memory leaks can quickly become a big problem for long-running applications, and a common source of memory leaks is detached DOM elements ......
Read more >
How can Detached DOM elements cause memory leak in ...
Detached DOM elements are the elements which have been removed from the DOM but their memory is still retained because of JavaScript.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found