doubt about C API resource release
Hi, good day,
As far as I know, all C API with a xx_create (call new and return a pointer) has a destroy func to free the memory, normally they should appear in pairs, but I have found some exception, I would to know if they are bugs or on purpose.
For example, rocksdb_slicetransform_create_fixed_prefix returns a point points to a wrapper struct, if I call set func rocksdb_options_set_prefix_extractor to set it to rocksdb_option, inside the set func it directly call reset(), then if I destroy the rocksdb_options and prefix itself, core dump happened. What will happen to rocksdb_filterpolicy_create_bloom_full is similar to that of prefix, they both return pointer to wapper struct and call reset() directly inside set func.
void rocksdb_options_set_prefix_extractor(
rocksdb_options_t* opt, rocksdb_slicetransform_t* prefix_extractor) {
opt->rep.prefix_extractor.reset(prefix_extractor);
}
Another situation is inside set func, a new struct will be built and reset to option, such as what happens in rocksdb_options_set_block_based_table_factory. I also found there is situation where bare pointer is directly assigned, rocksdb_options_set_comparator for example, and shared_ptr directly assigned, rocksdb_block_based_options_set_block_cache.
The destroy function cannot be called in some cases make me feel confused. Are there any clear guidelines for resource release?
BTW, I have found that if I finish read, after closed the db by rocksdb_close, destroyed the rocksdb_option and table open and block cache, memory used by block cache are not all freed (only part of), is that rational? What should I do to let the block cache memory all freed and returned to sys?