C++ Deleting Static Data

后端 未结 5 1456
难免孤独
难免孤独 2021-02-12 11:47

If I have a class that contains private static data allocated on the heap that never changes, when, if at all, should I delete it?

As I understand it, a class itself is

5条回答
  •  时光取名叫无心
    2021-02-12 12:09

    You can place this class in std::unique_ptr. Then it will be deleted automatically on program shutdown. Otherwise memory leak tools will complain, that your class leaks. On the other hand this memory leak is harmless because the program finished running.

提交回复
热议问题