开发者

Do I need to free each individual element in a struct?

If I have a struct of ints, do I have to individually fr开发者_如何学Goee all of the ints (they are not pointers), or will they be freed when I call free() on the struct?


No, they will be freed when the entire struct is freed.

(Note that you only need to free a struct that was allocated with malloc/calloc/realloc, not one that was allocated on a stack.)


malloc and free go in pairs.
If you did not allocate memory dynamically for it, don't free it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜