且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

释放已分配给char指针(字符串)数组的内存.我必须释放每个字符串还是仅释放"main"字符串?指针?

更新时间:2023-02-17 14:38:59

那不只是释放实际的指针,而不是释放每个字符串本身正在使用的内存吗?

won't that just free the actual pointers and not the memory each string itself was using?

是的.

我如何完全释放内存

How do I completely free the memory

通过遍历数组并在 释放数组本身之前一一释放每个字符串.例如

By looping through the array and freeing each string one by one before freeing up the array itself. E.g.

for (i = 0; i < SOMETHING; i++) {
    free(list[i]);
}
free(list);