When would the garbage collector erase an instance of an object that uses Singleton pattern?

后端 未结 4 1467
夕颜
夕颜 2020-12-01 05:14

When would the garbage collector erase an instance of an object that uses Singleton pattern?

Does an object hang around any longer than a regular object?

How

4条回答
  •  生来不讨喜
    2020-12-01 06:01

    If you're keeping a static reference to it in your singleton class, then the reference count cannot drop to 0 and therefore it shouldn't ever get collected.

提交回复
热议问题