diff --git a/test/support/src/mem_helpers.cc b/test/support/src/mem_helpers.cc index c92f0cab85f..50a18ad5b26 100644 --- a/test/support/src/mem_helpers.cc +++ b/test/support/src/mem_helpers.cc @@ -35,15 +35,25 @@ namespace tiledb::test { -shared_ptr create_test_memory_tracker() { +shared_ptr get_test_memory_tracker() { class MemoryTrackerCreator : public sm::MemoryTracker { public: MemoryTrackerCreator() : sm::MemoryTracker() { } + + static shared_ptr get_instance() { + static shared_ptr tracker{ + new MemoryTrackerCreator()}; + return tracker; + } }; - return make_shared(HERE()); + return MemoryTrackerCreator::get_instance(); +} + +shared_ptr create_test_memory_tracker() { + return get_test_memory_tracker(); } } // namespace tiledb::test diff --git a/test/support/src/mem_helpers.h b/test/support/src/mem_helpers.h index 96a359a1975..363a1e78a76 100644 --- a/test/support/src/mem_helpers.h +++ b/test/support/src/mem_helpers.h @@ -38,6 +38,18 @@ namespace tiledb::test { +/** + * Helper function get the test instance of a shared_ptr + * + * This is the preferred function. The create_test_memory_tracker will be + * replaced shortly and only serves as a proxy to this function while we + * transition the first few PRs to use this new function. + * + * The reasoning here is that creating memory trackers has turned out to be a + * bit of a footgun with lifetime issues. + */ +shared_ptr get_test_memory_tracker(); + /** * Helper function to create test instances of shared_ptr */