Use case of folly Indestructible

76 Views Asked by At

I came across this feature from folly https://github.com/facebook/folly/blob/main/folly/Indestructible.h#L51

*  This is designed as an alternative, but with one fewer allocation at
 *  construction time and one fewer pointer dereference at access time, to the
 *  Meyers singleton pattern of:
 *
 *    void doSomethingWithExpensiveData() {
 *      static const auto data =  // never `delete`d
 *          new map<string, int>{{"key1", 17}, {"key2", 19}, {"key3", 23}};
 *      callSomethingTakingAMapByRef(*data);
 *    }

What is a valid use case for this feature? Will this cause a memory leak since it's never freed?

0

There are 0 best solutions below