The following declaration in the file generated by grpc (grpc.pb.cc) causes a memory leak. It seems that google::protobuf::ShutdownProtobufLibrary() does not free the memory allocated by this declaration. Would you tell me how to release it?
PROTOBUF_ATTRIBUTE_INIT_PRIORITY static ::PROTOBUF_NAMESPACE_ID::internal::AddDescriptorsRunner dynamic_init_dummy_DxpGrpc_2eproto(&descriptor_table_DxpGrpc_2eproto);
Windows, C ++, gRPC-1.40.0
Create a console application in the Windows c++ environment and execute the following code.
#include <crtdbg.h>.
#include "google/protobuf/service.h";
int main(int argc, char** argv) {
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
google::protobuf::ShutdownProtobufLibrary();
return 0;
}
The following leaks will be out.
Detected memory leaks!
Dumping objects -> {159}
{Normal block at 0x00E49B18, 8 bytes long.
Data: < k > 10 6B C9 00 00 00 00 00
Object dump complete.
When declare AddDescriptorsRunner in grpc.pb.cc, it calls DefaultConstruct() of the following class.
(File: third_party\protobuf\src\google\protobuf\message_lite.h)
template <typename T>.
class ExplicitlyConstructed {
public:
void DefaultConstruct() { new (&union_) T(); }
template <typename... Args>
void Construct(Args&&... args) {
new (&union_) T(std::forward<Args>(args)...) ;
}
void Destruct() { get_mutable()->~T(); }
constexpr const T& get() const { return reinterpret_cast<const T&>(union_); }
T* get_mutable() { return reinterpret_cast<T*>(&union_); }
private:
// Prefer c++14 aligned_storage, but for compatibility this will do.
union AlignedUnion {
alignas(T) char space[sizeof(T)];
int64 align_to_int64;
void* align_to_ptr;
} union_;
};