Commit 2ef90158 authored by Franziska Hinkelmann's avatar Franziska Hinkelmann Committed by Commit Bot

[heap-profiler] Use unique ptr for snapshots for explicit ownership

Implement empty desctructor because of the forward declarations.

Change-Id: I56af92d7ded44b6fcd3582d1e3a10e9bb5cb1296
Reviewed-on: https://chromium-review.googlesource.com/905671Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Commit-Queue: Franziska Hinkelmann <franzih@chromium.org>
Cr-Commit-Position: refs/heads/master@{#51180}
parent da159ccc
......@@ -19,25 +19,20 @@ HeapProfiler::HeapProfiler(Heap* heap)
names_(new StringsStorage(heap)),
is_tracking_object_moves_(false) {}
static void DeleteHeapSnapshot(HeapSnapshot* snapshot_ptr) {
delete snapshot_ptr;
}
HeapProfiler::~HeapProfiler() {
std::for_each(snapshots_.begin(), snapshots_.end(), &DeleteHeapSnapshot);
}
HeapProfiler::~HeapProfiler() = default;
void HeapProfiler::DeleteAllSnapshots() {
std::for_each(snapshots_.begin(), snapshots_.end(), &DeleteHeapSnapshot);
snapshots_.clear();
names_.reset(new StringsStorage(heap()));
}
void HeapProfiler::RemoveSnapshot(HeapSnapshot* snapshot) {
snapshots_.erase(std::find(snapshots_.begin(), snapshots_.end(), snapshot));
snapshots_.erase(
std::find_if(snapshots_.begin(), snapshots_.end(),
[&](const std::unique_ptr<HeapSnapshot>& entry) {
return entry.get() == snapshot;
}));
}
......@@ -96,7 +91,7 @@ HeapSnapshot* HeapProfiler::TakeSnapshot(
delete result;
result = nullptr;
} else {
snapshots_.push_back(result);
snapshots_.emplace_back(result);
}
}
ids_->RemoveDeadEntries();
......@@ -164,7 +159,7 @@ int HeapProfiler::GetSnapshotsCount() {
}
HeapSnapshot* HeapProfiler::GetSnapshot(int index) {
return snapshots_.at(index);
return snapshots_.at(index).get();
}
SnapshotObjectId HeapProfiler::GetSnapshotObjectId(Handle<Object> obj) {
......
......@@ -91,7 +91,7 @@ class HeapProfiler {
// Mapping from HeapObject addresses to objects' uids.
std::unique_ptr<HeapObjectsMap> ids_;
std::vector<HeapSnapshot*> snapshots_;
std::vector<std::unique_ptr<HeapSnapshot>> snapshots_;
std::unique_ptr<StringsStorage> names_;
std::vector<v8::HeapProfiler::WrapperInfoCallback> wrapper_callbacks_;
std::unique_ptr<AllocationTracker> allocation_tracker_;
......
......@@ -184,7 +184,6 @@ HeapSnapshot::HeapSnapshot(HeapProfiler* profiler)
void HeapSnapshot::Delete() {
profiler_->RemoveSnapshot(this);
delete this;
}
......
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