Releasing the resources of a stack allocated 'as_integer'

I wanted to know if it’s required to call ‘as_integer_destroy’ on a stack allocated as_integer. As per the documentation it seems that it has to be called in both cases i.e. stack/heap allocation. Just wanted to be sure. Thanks!

No. as_integer_destroy() is not required on a stack allocated as_integer. I will modify that documentation to be more clear.

Hi Brian, Thanks for the quick reply. Just wanted to highlight that this ambiguity is there in the documents of several other data structures as well(aerospike, as_key, as_hashmap, as_string etc.) Does your reply apply to all of the other stack allocated data structures?

No. All of the structures you mention (ie as_string) contain underlying data structures (ie. char* value) that may or may not be heap allocated. This is why the documentation says to always use the structure’s destroy() function. This function knows when variables are heap allocated or not and works in both cases.

If you don’t want to call the structure’s destroy() function, you must have a deep understanding of the api and data structures to ensure it’s the appropriate thing to do.

Hi Brian, Thanks for your quick response once again. My takeaway from this discussion is to always use the structure’s destroy function(even if it’s stack allocated), unless I’m sure that all of its underlying members are also stack allocated. However, it would’ve been better if it would’ve been explicitly stated in the documentation, for each data structure, under what scenarios the destroy function is needed because to call the destroy function in all cases isn’t very performance optimised.

© 2015 Copyright Aerospike, Inc. | All rights reserved. Creators of the Aerospike Database.