Skip to content

Commit afacf89

Browse files
committed
Try deleting later.
1 parent 9a681d6 commit afacf89

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

src/sample.cpp

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -466,13 +466,25 @@ sample *factory::pop_freelist() {
466466
}
467467

468468
factory::~factory() {
469-
sample *cur = tail_;
470-
while (cur) {
471-
sample *next = cur->next_; // Save next pointer before potentially deleting cur
472-
if (cur != sentinel()) delete cur;
473-
cur = next;
474-
}
475-
delete[] storage_;
469+
// get pending samples
470+
std::vector<sample*> pending;
471+
sample *cur = tail_.load();
472+
473+
// add them without deleting
474+
while (cur) {
475+
if (cur != sentinel()) {
476+
pending.push_back(cur);
477+
}
478+
sample *next = cur->next_.load();
479+
cur = next;
480+
}
481+
482+
// now delete the samples
483+
for (sample* s : pending) {
484+
delete s;
485+
}
486+
487+
delete[] storage_;
476488
}
477489

478490
void factory::reclaim_sample(sample *s) {

0 commit comments

Comments
 (0)