LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-04-2007, 07:23 AM   #1
Genar
LQ Newbie
 
Registered: Feb 2007
Posts: 2

Rep: Reputation: 0
Singleton delete instance


In a simple Singleton pattern written in C++ how is it possible to delete the instance? (Apparently this pattern is very simple but I have realized that, in a lot of implementations, the instance was not really deleted). As the user member "dmail" commented, he uses a "getinstance" function to get a reference (a pointer is also possible) to the instance created, then he also registers an "atexit" function to delete the instance.

But, does not exist another solution without registering an atexit function in order to delete the instance?
Thanks.
 
Old 03-04-2007, 09:34 AM   #2
dmail
Member
 
Registered: Oct 2005
Posts: 970

Rep: Reputation: Disabled
Actually the code I use has as a template parameter which is scope of the singleton, "user deletes" or "app exit". As it would sound, with app exit the class registers the atexit func and user deletes would leak memory if the user did not delete it. Have at look at loki's source code for more advanced scoping of singletons http://loki-lib.sourceforge.net/.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to make singleton application in C++ manishpatidar Linux - Software 1 05-30-2006 06:27 PM
c++: Problems with a singleton (as a so) eantoranz Programming 11 02-20-2006 09:38 AM
Triple check singleton pattern dmail Programming 0 12-19-2005 08:56 AM
singleton pattern in C++? Thinking Programming 7 11-13-2005 07:45 PM
script in same instance Manish Linux - General 2 02-23-2002 12:03 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:47 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration