Suppose I have a global variable that contains a large structure:
typedef struct {
char Big[1024]
} LARGE;
static LARGE x;
void main()
{
free(x);
}
Can I safely call free(x) from main when I dont need it anymore?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
No. You didn’t dynamically allocate
xso don’t need to (and cannot) free it.If you absolutely need to free the memory before your program exits, declare a pointer as global, allocate it on demand, using
mallocorcalloc, thenfreeit when you’re finished with the structure.