how to delete singleton object

前端 未结 3 639
不知归路
不知归路 2021-01-19 10:49

Assuming this implementation of a singleton pattern ( of course we should avoid Singleton: it is just question), I have just been thinking about static object being created.

3条回答
  •  抹茶落季
    2021-01-19 11:18

    Part of the Singleton design pattern is that it is indestructible.

    EDIT:

    There are 2 varieties of singletons with respect to destructibility:

    1. Destructible (They die when the application does)
    2. Indestructible (They die when the machine does)

    Either way, if built properly, once the singleton instance is created, it stays. This one of the major criticisms of the Singleton design pattern.

    Here are a few references that address the destructibility aspect of the pattern.

    http://nicolabonelli.wordpress.com/2009/06/04/singleton-a-mirage-of-perfection/ http://www10.informatik.uni-erlangen.de/Teaching/Courses/SS2009/CPP/altmann.pdf http://sourcemaking.com/design_patterns/singleton http://sourcemaking.com/design_patterns/to_kill_a_singleton

提交回复
热议问题