As Singletons may have object level variables which may never get cleaned up and may cause memory leaks.
Hence, I would suggest having all the methods static in the class.
Input would be appreciated.
-Jam
-
Prefer Static methods to Singleton (3 messages)
- Posted by: Ram Jam
- Posted on: October 18 2004 12:56 EDT
Threaded Messages (3)
- Prefer Static methods to Singleton by josef betancourt on October 18 2004 15:10 EDT
- Prefer Static methods to Singleton by Sanjaya Ganesh on October 19 2004 04:17 EDT
- fix the problem by bruce goldstein on October 22 2004 09:06 EDT
-
Prefer Static methods to Singleton[ Go to top ]
- Posted by: josef betancourt
- Posted on: October 18 2004 15:10 EDT
- in response to Ram Jam
Static methods can access static fields that could still cause problems. -
Prefer Static methods to Singleton[ Go to top ]
- Posted by: Sanjaya Ganesh
- Posted on: October 19 2004 04:17 EDT
- in response to Ram Jam
As Singletons may have object level variables which may never get cleaned up and may cause memory leaks.Hence, I would suggest having all the methods static in the class.Input would be appreciated.-Jam
A static has exactly the same problem except that the variables are static now. How is that a solution? That is just a different problem :-), not a solution to the problem you have -
fix the problem[ Go to top ]
- Posted by: bruce goldstein
- Posted on: October 22 2004 09:06 EDT
- in response to Ram Jam
The problem is not singletons. The problem is you need to define your strategy to release or cleanup resources. If you write a cache thats implementated as a singleton it can grow into a huge memory leak. Or you can choose to evict data from the cache every so often or cap the size. Either way there is only a memory leak if you allow it. Note that any java program will crash if you do not conserver your resources as memory is finite. Do not blame singleton. Just come up with a method for convserving and cleaning up your resources. Note that WeakHashMaps can be nice.
Bruce