有一个结构:
struct list
{
struct list *next;
int temp;
};
用下面的方法释放:
// free linked list
struct list *head_list = NULL;
struct list *current_list = NULL;
struct list *prev_list = NULL;
current_list = head_list;
while (current_file_info_arr != NULL)
{
prev_list = current_list;
current_list = current_list->next;
free(prev_list);
}
结果报了警报:
Memory error
Use of memory after it is freed
不知道警报应该怎么解决?
虽然我不用xcode……但是,感觉你应当在释放后把指针移动回去,你把当前的释放了以后它就没有next了