mongoc_init_cleanup man page

mongoc_init_cleanup — Initialization and cleanup


Initialize the MongoDB C Driver by calling mongoc_init exactly once at the beginning of your program. It is responsible for initializing global state such as process counters, SSL, and threading primitives.

Call mongoc_cleanup exactly once at the end of your program to release all memory and other resources allocated by the driver. You must not call any other MongoDB C Driver functions after mongoc_cleanup. Note that mongoc_init does not reinitialize the driver after mongoc_cleanup.

Deprecated Feature: Automatic Initialization and Cleanup

On some platforms the driver can automatically call mongoc_init before main, and call mongoc_cleanup as the process exits. This is problematic in situations where related libraries also execute cleanup code on shutdown, and it creates inconsistent rules across platforms. Therefore the automatic initialization and cleanup feature is deprecated, and will be dropped in version 2.0. Meanwhile, for backward compatibility, the feature is enabled by default on platforms where it is available.

For portable, future-proof code, always call mongoc_init and mongoc_cleanup yourself, and configure the driver like:

./configure --disable-automatic-init-and-cleanup

Or with CMake:



MongoDB, Inc


Feb 02, 2017 1.6.0 MongoDB C Driver