Hi Everyone,

I have a program built on VS 2005 which compiles fine, and when I execute the same, it runs as expected. But i see memory leaks being detected by tools like (Visual Leak Detector, Glow Code etc..), Below is the block of code for your reference.

void Argument(const T &arg)
{
std::stringstream ss;
ss >> arg;
m_argument.push_back(ss.str());
}

can anyone help me in fixing this memory leaks

Thanks
Sam

Recommended Answers

All 6 Replies

>Below is the block of code for your reference.
Are you using a custom allocator?

>Below is the block of code for your reference.
Are you using a custom allocator?

Hi Narue,

Thanks for your immediate response, at this point of time i'm not sure on your question, as i dont have the entire code with me.

>at this point of time i'm not sure on your question
So are we talking about a codebase that's a team effort or otherwise isn't written entirely by you?

>Below is the block of code for your reference.
Are you using a custom allocator?

Hi Narue,

The code is not written by me, and can you please suggest me the solution considering it either ways (custom allocator / default allocator), your help in this regard is highly appreciable.

I can't tell you where your problem is. I'm not quite that psychic. But I can tell you that if you have a custom allocator on m_argument, it's very possible that a bug in the allocator is leaking memory or somehow creating false positives for your leak detectors. If you don't have a custom allocator, that snippet is not likely to be the problem (assuming m_argument is a standard container). Memory leaks typically come from places where you manage memory manually, not where it's managed for you in a library.

Standard libraries are generally quite mature and obvious problems like this are weeded out because they're used a lot by a lot of people. So your first course of action is to blame your code, and not any libraries you use.

I can't tell you where your problem is. I'm not quite that psychic. But I can tell you that if you have a custom allocator on m_argument, it's very possible that a bug in the allocator is leaking memory or somehow creating false positives for your leak detectors. If you don't have a custom allocator, that snippet is not likely to be the problem (assuming m_argument is a standard container). Memory leaks typically come from places where you manage memory manually, not where it's managed for you in a library.

Standard libraries are generally quite mature and obvious problems like this are weeded out because they're used a lot by a lot of people. So your first course of action is to blame your code, and not any libraries you use.

Thank you for sharing the useful information..appreciated your help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.