I designed my application to run such that I call a raw pointer on a class deriving from a Singleton:
class SimulatedIndexFixingStore : public Singleton<SimulatedIndexFixingStore>
{
private:
friend Singleton<SimulatedIndexFixingStore>;
typedef std::unordered_map<std::string, std::unordered_map<int, std::map<Date, double>>> Dictionary;
mutable Dictionary simulatedFixings_;
SimulatedIndexFixingStore& operator=(const SimulatedIndexFixingStore& ) = delete;
SimulatedIndexFixingStore(const SimulatedIndexFixingStore& ) = delete;
SimulatedIndexFixingStore();
~SimulatedIndexFixingStore()
{
std::cout << "\nCalling destructor of store...\n";
}
public:
// creates raw pointers to this store and passes them around...
static SimulatedIndexFixingStore* createPointerToStore()
{
auto tmp = new SimulatedIndexFixingStore() <----- memory allocation on the heap!;
return tmp;
}
};
I then use the raw pointer generated by the static member function SimulatedIndexFixingStore* createPointerToStore() and pass them around my application.
Question:
I don't call delete on the pointer prior to leaving the Main() function as this would call the destructor on the static Singleton instance, so this means I have a memory leak in my app. Correct?
I know for a fact that the destructor ~ SimulatedIndexFixingStore() is not getting called because the message is not printed out.
The instrument profiler of my application doesn't seem to agree there is a memory leak. Can someone please help me understand?
Thanks, Amine