Talk:C++ Programming/Code/Design Patterns/Creational Patterns

Code sample for singleton
what about memory leak? --84.237.120.178 (talk) 04:58, 8 February 2008 (UTC)


 * Can you be more specific ? --Panic (talk) 16:40, 8 February 2008 (UTC)


 * There is operator new in the function Instance. There is private destructor in the class StringSingleton. So, we cannot delete instance in the outer scope and there is no operator delete in the class StringSingleton. Memory leak? --84.237.120.178 (talk) 14:15, 13 February 2008 (UTC)

Memory Leak and Virtual destructor error.
Any virtual member, creates the need for a virtual destructor! Far Worse then just a memory leak...... IF any member function is virtual, then the destructor must be virtual! This is a rule! Otherwise, the derived class destructor is not called. If you ignore this rule, because this is trivial, you've created a silly error because there is a non-virtual default destructor (ouch), you are wrong...and likely on some systems, this will not compile! You are also "deleting" a pointer you do not own. You created the class, and get returns an internal pointer. "get" as a function, is WRONG. This allowed the other error, where someone was deleting an internal pointer! I'll try to correct, but it's going to be quite a bit of deleting. The factory implementation, returns a base class pointer, for a derived class. 75.107.140.75 (discuss) 01:23, 7 September 2014 (UTC)