1

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

4

1 回答 1

0

看到这些,

设计模式:单例模式,优缺点

单例模式——积极和消极方面

辛格尔顿

于 2018-11-04T06:09:20.353 回答