[√]关于 Dynamic atexit destructor for ***

简介: [√]关于 Dynamic atexit destructor for ***

image.png

分析

Dynamic atexit destructor for ***是一个编译器提示或警告消息,用于指示存在动态的析构函数注册(atexit destructor)。

在C++中,当程序退出时,静态对象和全局对象的析构函数会被自动调用来执行清理操作。这些静态对象和全局对象的析构函数通常是通过静态初始化完成的。

然而,有些情况下,可能存在动态创建的对象需要在程序退出时进行清理,例如使用new运算符动态分配的对象。为了确保这些动态对象也能在程序退出时正确地进行清理,可以使用atexit函数来注册析构函数。

当编译器检测到有动态的析构函数注册时,会生成类似于"Dynamic atexit destructor for ***"的提示或警告消息,以提醒开发者可能存在一些资源管理的问题。

如果你看到了这样的消息,可以进一步检查代码,确保动态分配的对象能够被正确释放和清理。

解决办法

一般遇到这个 call stack 很可能是全局变量析构函数中有依赖导致的。这个 call stack 会很短(因为有可能是任何情况导致程序退出),直接分析可能找不出原因。

至于全局变量的析构顺序,c++中没有明确定义,一般各个编译器实现为:根据构造的顺序逆向析构。

但是全局变量的构造又是很难控制的,以为各个全局变量会分布在不同的cpp文件中(编译单元)。

所以最好不要在全局变量的析构函数中做任何的清除工作,也不要让全局变量的析构函数之间有任何相互调用或依赖!

目录
相关文章
|
机器学习/深度学习 并行计算 程序员
成功解决 This graphics driver could not find compatible graphics hardware. You maycontinue installation,
成功解决 This graphics driver could not find compatible graphics hardware. You maycontinue installation,
成功解决 This graphics driver could not find compatible graphics hardware. You maycontinue installation,
Simple TimerCallable Support
我们知道使用Callable可以获得线程中的返回值,它在 java.util.concurrent 包中声明。此接口还包含一个单一的、无参数的cal方法,此方法与Runnable接口的run方法类似,只是它可以返回一个值,并且可以抛出一个已检查的异常。事实上Callable也是Runnable,因为这两个接口都指定了一个有可能被另一个线程执行的类,只是它不受Runnable的限制。
99 0
Simple TimerCallable Support
|
云计算
Google Earth Engine(GEE)——Error: Exported bands must have compatible data types; found inconsistent
Google Earth Engine(GEE)——Error: Exported bands must have compatible data types; found inconsistent
496 0
Google Earth Engine(GEE)——Error: Exported bands must have compatible data types; found inconsistent
|
编解码 知识图谱
Google Earth Engine ——MOD17A3HGF.006: Terra Net Primary Production Gap-Filled Yearly Global 500m
Google Earth Engine ——MOD17A3HGF.006: Terra Net Primary Production Gap-Filled Yearly Global 500m
349 0
Google Earth Engine ——MOD17A3HGF.006: Terra Net Primary Production Gap-Filled Yearly Global 500m
SAP gateway standard mode和compatible mode的区别
SAP gateway standard mode和compatible mode的区别
138 0
SAP gateway standard mode和compatible mode的区别
|
Python
Cannot mix incompatible Qt library (version 0x50907) with this library (version 0x50e02)
Cannot mix incompatible Qt library (version 0x50907) with this library (version 0x50e02)
773 0
|
Oracle 关系型数据库 Unix
ACFS Support On OS Platforms (Certification Matrix). (文档 ID 1369107.1)
A) The next matrix provides a roadmap for ACFS support platforms and versions:   ACFS 11.2.0.1 Supported Platforms Vendor Version Update/Kernel Arc.
2485 0