1class InfiniteScroll {
2 constructor(container) {
3 this.items = [];
4 this.container = container;
5 }
6
7 addItem(data) {
8 const el = document.createElement('div');
9 el.textContent = data.title;
10 el.addEventListener('click', () => this.handleClick(data));
11 this.container.appendChild(el);
12 this.items.push(el);
13 }
14
15 reset() {
16 this.container.innerHTML = '';
17 this.items = [];
18 }
19}
no lines flagged
#015PracticeHard30 min · 200 XP
Memory Leak via Detached DOM Listener
Event listeners attached to dynamically created elements are never removed, causing a memory leak over time.
Flagged linesNo lines flagged yet
What's wrong?
Flag a line or write a note to submit.