I’ve encountered a problem which is i can’t correctly deallocate memory. I have a vector of type int*
and
after allocating memory and adding these pointers to my vector, i just want to deallocate the memory and end the program.
std::vector<int*> students;
students.push_back(new int);
students.push_back(new int);
students.push_back(new int);
students.push_back(new int);
students.push_back(new int);
students.push_back(new int);
students.push_back(new int);
for (const auto& student : students) {
delete student;
}
students.clear();
_CrtDumpMemoryLeaks();
But, i get the following output from my visual studio 2022:
Detected memory leaks!
Dumping objects ->
{170} normal block at 0x000001C4AAE05BF0, 72 bytes long.
Data: <# # > 23 81 00 00 00 00 00 00 23 81 00 00 00 00 00 00
{157} normal block at 0x000001C4AAE11E80, 16 bytes long.
Data: < u: > C8 F5 75 3A AF 00 00 00 00 00 00 00 00 00 00 00
Object dump complete.
I just don’t understand. First, i faced this problem with more complicated project than this (project comprised of classes and other stuff) and i thought maybe the problem with memory leaks was somewhere in destructors or idk, but.. idk…
p.s. to detect memory leaks i use crtdbg.h
Help me correctly deallocate memory please
alex is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.