所以我有一个链接列表得到正确创建,正确链接,但当我试图取消分配内存我似乎无法删除任何节点,该列表仍然存在。 代码为我的列表解构:我不明白我在做什么错我的记忆解除分配
void LL_User::free_memory() {
// TODO
LL_User_Node *currentNode;
currentNode = head;
while(currentNode) {
LL_User_Node *temp = currentNode;
currentNode = currentNode->next;
delete temp;
}
//cout << "LL_User::free_memory() is not implemented yet.\n";
}
LL_User::~LL_User() {
if(head == NULL) {
return;
}
free_memory();
}
而且我的用户类有本作的VAR和析构:
User::User() {
username = "";
password = "";
first_name = "";
last_name = "";
profile_pic_filename = "";
birth_year = 0;
birth_month = 0;
birth_day = 0;
}
User::~User() {
//Nothing placed in body because strings and ints are dealt with by OS?
}
为什么你的'free'变量在'free_memory'函数中?! – emartel
'currentNode = head;'创建一个内存泄漏。 – andre