.\" Man page generated from reStructuredText. . . .nr rst2man-indent-level 0 . .de1 rstReportMargin \\$1 \\n[an-margin] level \\n[rst2man-indent-level] level margin: \\n[rst2man-indent\\n[rst2man-indent-level]] - \\n[rst2man-indent0] \\n[rst2man-indent1] \\n[rst2man-indent2] .. .de1 INDENT .\" .rstReportMargin pre: . RS \\$1 . nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin] . nr rst2man-indent-level +1 .\" .rstReportMargin post: .. .de UNINDENT . RE .\" indent \\n[an-margin] .\" old: \\n[rst2man-indent\\n[rst2man-indent-level]] .nr rst2man-indent-level -1 .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]] .in \\n[rst2man-indent\\n[rst2man-indent-level]]u .. .TH "BSON_LIFETIMES" "3" "Feb 25, 2024" "1.26.0" "libbson" .sp A \fI\%bson_t\fP may contain its data directly or may contain pointers to heap\-allocated memory. Overwriting an existing \fI\%bson_t\fP or allowing a stack\-allocated \fI\%bson_t\fP to go out of scope may cause a memory leak. A \fI\%bson_t\fP should always be destroyed with \fI\%bson_destroy()\fP\&. .SH BSON_T OUT PARAMETERS .sp A \fI\%bson_t\fP pointer used as an out parameter must point to valid overwritable storage for a new \fI\%bson_t\fP which must be one of: .INDENT 0.0 .IP 1. 3 Uninitialized storage for a \fI\%bson_t\fP\&. .IP 2. 3 A zero\-initialized \fI\%bson_t\fP object. .IP 3. 3 A \fI\%bson_t\fP object initialized with \fBBSON_INITIALIZER\fP\&. .IP 4. 3 A \fI\%bson_t\fP object not created with \fI\%bson_new()\fP that was destroyed with \fI\%bson_destroy()\fP\&. .UNINDENT .sp This can be on the stack: .INDENT 0.0 .INDENT 3.5 .sp .EX bson_t stack_doc = BSON_INITIALIZER; example_get_doc (&stack_doc); bson_destroy (&stack_doc); .EE .UNINDENT .UNINDENT .sp Or on the heap: .INDENT 0.0 .INDENT 3.5 .sp .EX bson_t *heap_doc = bson_malloc (sizeof (bson_t)); example_get_doc (heap_doc); bson_destroy (heap_doc); bson_free (heap_doc); .EE .UNINDENT .UNINDENT .sp Omitting \fI\%bson_destroy()\fP in either case may cause memory leaks. .sp \fBWARNING:\fP .INDENT 0.0 .INDENT 3.5 Passing a \fI\%bson_t\fP pointer obtained from \fI\%bson_new()\fP as an out parameter will result in a leak of the \fI\%bson_t\fP struct. .INDENT 0.0 .INDENT 3.5 .sp .EX bson_t *heap_doc = bson_new (); example_get_doc (heap_doc); bson_destroy (heap_doc); // Leaks the \(gabson_t\(ga struct! .EE .UNINDENT .UNINDENT .UNINDENT .UNINDENT .SH AUTHOR MongoDB, Inc .SH COPYRIGHT 2017-present, MongoDB, Inc .\" Generated by docutils manpage writer. .