std::unique_ptr not releasing memory when used with a custom deleter in C++17
I'm trying to configure This might be a silly question, but I'm facing an issue with `std::unique_ptr` in C++17 where it appears to not release the allocated memory as expected when I use a custom deleter. I have a custom class `Resource` that I am allocating dynamically, and I want to ensure that it is properly cleaned up. Here's the setup I have: ```cpp #include <iostream> #include <memory> class Resource { public: Resource() { std::cout << "Resource created" << std::endl; } ~Resource() { std::cout << "Resource destroyed" << std::endl; } }; void customDeleter(Resource* res) { std::cout << "Custom deleter called" << std::endl; delete res; } int main() { std::unique_ptr<Resource, decltype(&customDeleter)> ptr(new Resource(), customDeleter); return 0; } ``` When I compile and run this code, I see the message "Resource created", but there's no output for "Resource destroyed" or "Custom deleter called". I'm not sure what's happening here. I thought using a custom deleter would ensure that the resource gets cleaned up when the `unique_ptr` goes out of scope. I've checked that the `unique_ptr` is indeed being constructed correctly, but it seems the custom deleter is never being invoked. I've already verified that the `std::unique_ptr` is the proper type and that `customDeleter` is correctly passed as its second template parameter. Is there something I'm missing in the implementation, or could this be an issue with how I'm managing the pointer? Additionally, I am compiling this with g++ 9.3.0. Any insights would be greatly appreciated! I'm working on a API that needs to handle this. Is there a better approach?