当使用像 C++
这样没有自动垃圾收集器的语言时,我知道你必须使用析构函数来清理你的对象。但是“清理”的概念与非 OOP 语言有何关系。例如,在 C
中清理结构和内置类型的标准方法是什么?
举个具体的例子,在编写长时间运行的 C
进程时,清理的相关概念是什么?
最佳答案
根据 wikipedia垃圾收集入口
In computer science, garbage collection (GC) is a form of automatic memory management.
和
Garbage collection is often portrayed as the opposite of manual memory management, which requires the programmer to specify which objects to deallocate and return to the memory system.
在 C
语言中,没有自动内存管理 所以我们必须手动内存管理。无论程序(或程序员)分配(动态地,在运行时)内存,程序(或程序员)都需要显式释放内存,使用free()
功能。
未能释放分配的内存将导致memory leak .
关于c++ - 垃圾收集的概念与非 OOP 语言有何关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28938358/