Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions core/src/chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@ impl Chunk {

next_chunk
}

pub(crate) fn clear(&mut self) {
self.next = None;
self.prev = None;
}
}

impl ToString for Chunk {
Expand Down
18 changes: 18 additions & 0 deletions core/src/magic_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -811,3 +811,21 @@ impl ToString for MagicString {
format!("{}{}", str, self.outro)
}
}

impl Drop for MagicString {
fn drop(&mut self) {
// explicitly clear Rc RefCell cyclic references by setting them to
// None before dropping to avoid memory leak caused by reference cycles
self.last_chunk.borrow_mut().clear();
self.first_chunk.borrow_mut().clear();
self.last_searched_chunk.borrow_mut().clear();
self
.chunk_by_end
.iter_mut()
.for_each(|v| v.1.borrow_mut().clear());
self
.chunk_by_start
.iter_mut()
.for_each(|v| v.1.borrow_mut().clear());
}
}
Loading