| 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 ?
|
|
|