javamultithreadingmemory-leaksjava-memory-leaks

Benefits of Private Constructor - Singleton Design Pattern


I understand that it helps creates single copy of class.

I would like to know:

  1. What is the harm in creating multiple such instances of a class ? since garbage collection will take care of it.
  2. Is it that it helps when multiple classes/threads use it and Java may run out of memory ?
  3. It helps avoiding memory leak ?
  4. How to decide if singleton pattern is better for me use case ?

Or could you please lead me to resources that can be helpful to learn more about it.

Thanks


Solution

  • See these,

    Design Pattern: Singleton Pattern, pros & cons

    Singleton Pattern – Positive and Negative Aspects

    Singleton