File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes OO, Patterns, UML and Refactoring and the fly likes Singletion - memory issue ? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Reply Bookmark "Singletion - memory issue ?" Watch "Singletion - memory issue ?" New topic
Author

Singletion - memory issue ?

kri shan
Ranch Hand

Joined: Apr 08, 2004
Posts: 1248
I read in the web, Singleton class may give memory issue. If so, why we go for Singleton class?
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2207

When the Gang of Four wrote their Design Patterns book, the Singleton became one of the most popular patterns.
You could easily understand its mechanism, and everyone was looking for some mechanism to steer away from global defined functions and variables. We also found it useful that we could guarantee that only one instance of something would run at the same time.

History learned that Singletons do not guarantee that only a single instance runs, and that the pattern has some issues.
It is difficult to properly manage the life cycle of a Singleton (the memory issue you refer to). It adds complexity to unit testing. Critics started to point out that Singletons were merely a pseudo solution for global defined thingies, and classified it as an antipattern.

The pattern community has learned. New patterns have emerged that solve some of the problems that were originally addressed by Singleton pattern.


I would like to take the opportunity to honor the Gang of Four. They changed my mind. Some of the patterns they documented can be challenged, but they lifted reuse to another level. They provoked our thoughts.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 13842

kri shan wrote:I read in the web, Singleton class may give memory issue.


Who said that and what did they actually say? Asking people to comment on vague rumours is pretty pointless. Especially one that (to me anyway) sounds completely the opposite of the truth.
 
 
subject: Singletion - memory issue ?
 
Threads others viewed
jmx and invoking its methods in jboss
Use of Singleton Classes
Singleton and java garbage collection...and issue?
Questions About Being Static
IntelliJ Java IDE