Using new operator with objects always needed

Started by
11 comments, last by rip-off 12 years, 7 months ago

As noted repeatedly in Iatent's thread, properly cleaning up your arrays (via delete[] or using std::vectors) will prevent "false" positives in your leak detection tools when trying to find another memory leak that is, say, leaking fast enough to crash your program.

If the goal is faster code, you might consider skipping cleanup in release mode.
If the goal is easier code to write, it'll unfortunately only be counter-productive in the long run.


Funny thing is all the vectors I initiate show as giving memory leaks in VSC++ 2010. I don't allocate memory for them.


I get a memory leak detection here

void ProjectDoma::AddString(string str, float x, float y, int size, int fontnum)
{
if(fontnum == 0)
commonstrings_.push_back(StringDisplay(str, x, y, size));
}

and here

void ProjectDoma::ModifyLetter(float posx, float posy, float width, float height, float xoff, float yoff, float xadv, int fontnum)
{
if(fontnum == 0)
{

commonletters_.push_back(LetterFont(posx, posy, width, height, xoff, yoff, xadv));
}
}


These vectors aren't destroyed until the program is closed. Is that why I am getting memory leak notifications? Because the memory leak detector doesn't see them get destroyed for the length of the program?
Checking memory usage in task manager shows there is no memory leaks, the memory usage is consistent.
Advertisement
My VS2010 was glitching on my computer, so I unistalled it and went back to 2008.
I don't remember 2010's profiler correctly, but if you are using linux or mac this is a good tip:

$ valgrind --leak-check=full ./your_executable

[font="Arial"]Valgrind runs your program completely and reports what have been allocated, what have not, etc. in a very clear way.
I know it works for linux and mac, I don't know about windows though. Either way, check it out![/font]
Programming is an art. Game programming is a masterpiece!

These vectors aren't destroyed until the program is closed. Is that why I am getting memory leak notifications? Because the memory leak detector doesn't see them get destroyed for the length of the program?
[/quote]
It depends on the order of operations. If the vectors are global, they'll be destroyed, but perhaps after the memory leak checking is done.


Checking memory usage in task manager shows there is no memory leaks, the memory usage is consistent.
[/quote]
The task manager is unsuitable for this purpose.

This topic is closed to new replies.

Advertisement