Suppose I have a struct:
struct Foo {
std::set<int> nodes;
};
Foo foo;
After inserting some elements into nodes
of foo
, I want to release the memory that nodes
holds, and I get some inspirations from Is std::vector memory freed upon a clear?
Can
std::set<int>().swap(foo.nodes)
release the memory properly?
My question differs from how to free memory from a set. Since the int
is the built-in type, we cannot delete it as a pointer, which is considered in how to free memory from a set.
By the way, clear()
shall not release the memory.