While learning BFS from geekforgeek, I notice that there is no delete adj
for the new list<int>
array:
adj = new list<int>[V];
Will it cause a memory leak? For this question, I made a demo to using delete to release the memory explicitly.
#include <iostream>
#include <list>
#include <algorithm>
using namespace std;
int main()
{
list<int> *adj = new list<int>[3];
cout << adj->size() << endl;
delete adj;
}
delete
operation will cause coredump. So why does deleting pointer to list cause core dump? How to release the memory by new
operation?