There is a similar question here.
I have the following structure:
struct SimpleXY
{
double x;
double y;
};
struct SimpleEdge
{
SimpleXY first;
SimpleXY second;
}
struct SimpleEdgeList
{
uint num_edges;
SimpleEdge *SimpleEdges;
};
What is the proper way to free the memory hold by SimpleEdgeList? This is my current approach, but I wonder whether I should manually free first and second data field or not.
void Free(SimpleEdgeList *myList)
{
free(myList->SimpleEdges);
}
This is a C structure and I’m looking for a C like memory releasing.
You do not need to manually free the fields. When you free the memory referenced by
myList->SimpleEdgeList, the call tofree()will clean up the entire block of memory, including the two fields you mentioned. Since those fields don’t contain pointers to any other objects, you don’t need to descend into them to reclaim memory.