올바르게 링크 된 목록을 만들었으므로 올바르게 링크되었지만 메모리를 할당 해제하려고하면 삭제할 수없는 것처럼 보입니다. 노드가 있으면 목록이 여전히 존재합니다. 내 목록 deconstructor에 대한 코드 :내 메모리 할당 해제 문제가 무엇인지 이해할 수 없다.
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();
}
그리고 내 사용자 클래스가 바르와 deconstructor이 있습니다
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_memory' 함수에서'new' 변수를 사용합니까? – emartel
'currentNode = head;'는 메모리 누수를 생성합니다. – andre