As far as I know, all C API with a _xxcreate (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_fixedprefix returns a point points to a wrapper struct, if I call set func _rocksdb_options_set_prefixextractor 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_bloomfull is similar to that of prefix, they both return pointer to wapper struct and call reset() directly inside set func.
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_tablefactory.
I also found there is situation where bare pointer is directly assigned, _rocksdb_options_setcomparator for example, and shared_ptr directly assigned, _rocksdb_block_based_options_set_blockcache.
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 _rocksdbclose, 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?
Hi, good day,
As far as I know, all C API with a _xxcreate (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_fixedprefix returns a point points to a wrapper struct, if I call set func _rocksdb_options_set_prefixextractor 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_bloomfull is similar to that of prefix, they both return pointer to wapper struct and call reset() directly inside set func.
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_tablefactory. I also found there is situation where bare pointer is directly assigned, _rocksdb_options_setcomparator for example, and shared_ptr directly assigned, _rocksdb_block_based_options_set_blockcache.
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 _rocksdbclose, 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?