memory manage statistics

Summary:
Earlier Statistics object was a raw pointer. This meant the user had to clear up
the Statistics object after creating the database. In most use cases the database is created in a function and the statistics pointer is out of scope. Hence the statistics object would never be deleted.
Now Using a shared_ptr to manage this.

Want this in before the next release.

Test Plan: make all check.

Reviewers: dhruba, emayanke

Reviewed By: emayanke

CC: leveldb

Differential Revision: https://reviews.facebook.net/D9735
This commit is contained in:
Abhishek Kona
2013-03-27 11:27:39 -07:00
parent ecd8db0200
commit 63f216ee0a
8 changed files with 15 additions and 23 deletions

View File

@@ -101,7 +101,7 @@ static const char* FLAGS_db = nullptr;
static bool FLAGS_verify_checksum = false;
// Database statistics
static class leveldb::DBStatistics* dbstats;
static std::shared_ptr<leveldb::Statistics> dbstats;
// Sync all writes to disk
static bool FLAGS_sync = false;
@@ -1045,7 +1045,7 @@ int main(int argc, char** argv) {
} else if (sscanf(argv[i], "--statistics=%d%c", &n, &junk) == 1 &&
(n == 0 || n == 1)) {
if (n == 1) {
dbstats = new leveldb::DBStatistics();
dbstats.reset(new leveldb::DBStatistics());
}
} else if (sscanf(argv[i], "--sync=%d%c", &n, &junk) == 1 &&
(n == 0 || n == 1)) {
@@ -1131,8 +1131,5 @@ int main(int argc, char** argv) {
leveldb::StressTest stress;
stress.Run();
if (dbstats) {
delete dbstats;
}
return 0;
}