为什么我的程序会自动释放东西?
Why my program automatically frees things?
我正在尝试为一项大学任务编写程序,我收到了来自 Valgrind 的消息:
==4244== HEAP SUMMARY:
==4244== in use at exit: 300 bytes in 2 blocks
==4244== total heap usage: 5 allocs, 3 frees, 2,428 bytes allocate
我不知道这 3 个免费功能 是从哪里来的,因为 当我删除我所有的免费功能时,这 3 个 仍然存在。我认为当一个函数 returns 没有释放东西时,那就是内存泄漏的情况。
我的问题是:为什么不是? 函数在 returns 时是否会释放其中声明的所有内容?如果是这样,我怎么知道函数成功释放了其中声明的内容?
在源代码之外的代码中获取 malloc()ed 和 free()ed,例如库函数。 Valgrind 看到了所有这些。
我正在尝试为一项大学任务编写程序,我收到了来自 Valgrind 的消息:
==4244== HEAP SUMMARY:
==4244== in use at exit: 300 bytes in 2 blocks
==4244== total heap usage: 5 allocs, 3 frees, 2,428 bytes allocate
我不知道这 3 个免费功能 是从哪里来的,因为 当我删除我所有的免费功能时,这 3 个 仍然存在。我认为当一个函数 returns 没有释放东西时,那就是内存泄漏的情况。
我的问题是:为什么不是? 函数在 returns 时是否会释放其中声明的所有内容?如果是这样,我怎么知道函数成功释放了其中声明的内容?
在源代码之外的代码中获取 malloc()ed 和 free()ed,例如库函数。 Valgrind 看到了所有这些。