Commit be9ac2b2 authored by Franziska Hinkelmann's avatar Franziska Hinkelmann Committed by Commit Bot

[heap-profiler] Make ownership for samples explicit

Change-Id: Ic0e513e61e3bd1a8ac8f06a1f81c27d35a7d29af
Reviewed-on: https://chromium-review.googlesource.com/911249Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Commit-Queue: Franziska Hinkelmann <franzih@chromium.org>
Cr-Commit-Position: refs/heads/master@{#51253}
parent 73d60721
......@@ -76,11 +76,7 @@ SamplingHeapProfiler::~SamplingHeapProfiler() {
heap_->RemoveAllocationObserversFromAllSpaces(other_spaces_observer_.get(),
new_space_observer_.get());
for (auto sample : samples_) {
delete sample;
}
std::set<Sample*> empty;
samples_.swap(empty);
samples_.clear();
}
......@@ -101,7 +97,7 @@ void SamplingHeapProfiler::SampleObject(Address soon_object, size_t size) {
AllocationNode* node = AddStack();
node->allocations_[size]++;
Sample* sample = new Sample(size, node, loc, this);
samples_.insert(sample);
samples_.emplace(sample);
sample->global.SetWeak(sample, OnWeakCallback, WeakCallbackType::kParameter);
}
......@@ -123,8 +119,14 @@ void SamplingHeapProfiler::OnWeakCallback(
node = parent;
}
}
sample->profiler->samples_.erase(sample);
delete sample;
auto it = std::find_if(sample->profiler->samples_.begin(),
sample->profiler->samples_.end(),
[&sample](const std::unique_ptr<Sample>& s) {
return s.get() == sample;
});
sample->profiler->samples_.erase(it);
// sample is deleted because its unique ptr was erased from samples_.
}
SamplingHeapProfiler::AllocationNode*
......
......@@ -146,7 +146,7 @@ class SamplingHeapProfiler {
std::unique_ptr<SamplingAllocationObserver> other_spaces_observer_;
StringsStorage* const names_;
AllocationNode profile_root_;
std::set<Sample*> samples_;
std::set<std::unique_ptr<Sample>> samples_;
const int stack_depth_;
const uint64_t rate_;
v8::HeapProfiler::SamplingFlags flags_;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment