使用C操作MySQL,程序完成时使用Valgrind检测,发现有内存泄漏。
==4785== LEAK SUMMARY:
==4785== definitely lost: 0 bytes in 0 blocks
==4785== indirectly lost: 0 bytes in 0 blocks
==4785== possibly lost: 0 bytes in 0 blocks
==4785== still reachable: 65,432 bytes in 17 blocks
==4785== suppressed: 0 bytes in 0 blocks
使用mysql_library_end()函数来释放剩余的内存。
This function finalizes the MySQL library. Call it when you are done using the library (for example, after disconnecting from the server). The action taken by the call depends on whether your application is linked to the MySQL client library or the MySQL embedded server library. For a client program linked against the libmysqlclient
library by using the -lmysqlclient
flag, mysql_library_end()
performs some memory management to clean up. For an embedded server application linked against the libmysqld
library by using the -lmysqld
flag, mysql_library_end()
shuts down the embedded server and then cleans up.