struct TIdCategory
{
string category;
string id;
};
class CMyClass: public IMyClass
{
public :
CMyClass(const string& id, const string category);
virtual ~CMyClass();
....
....
private :
TIdCategory m_userCategory;
....
};
CMyClass::CMyClass(const string& id, const string category)
{
m_userCategory.id=id;
m_userCategory.category=category; <---------------------- Here it
giving Memory Leak by Purify
}
I am creating CMyClass object by new.
1) Why it is giving Memory Leak by Purify in string assigment ?
2) Is that really MLK?
3) If it is really MLK then in id assigment why it is not giving MLK?
-ashok
|
|
0
|
|
|
|
Reply
|
ashokjis (4)
|
4/29/2010 11:53:47 AM |
|
On 4/29/2010 7:53 AM, Guru wrote:
> struct TIdCategory
> {
> string category;
> string id;
> };
>
> class CMyClass: public IMyClass
> {
> public :
> CMyClass(const string& id, const string category);
> virtual ~CMyClass();
> ....
> ....
> private :
> TIdCategory m_userCategory;
> ....
> };
>
> CMyClass::CMyClass(const string& id, const string category)
Why is 'id' passed by ref-to-const and 'category' by value?
> {
> m_userCategory.id=id;
> m_userCategory.category=category;<---------------------- Here it
> giving Memory Leak by Purify
> }
>
>
> I am creating CMyClass object by new.
>
> 1) Why it is giving Memory Leak by Purify in string assigment ?
Who knows? I've not used Purify in years, and don't recall what exactly
it reports. Does it say whether it's the member of 'm_userCatergory'
that leaks or the argument 'category'?
> 2) Is that really MLK?
What's MLK? Martin Luther King? You think his ghost affects Purify's
behavior?
> 3) If it is really MLK then in id assigment why it is not giving MLK?
>
> -ashok
V
--
I do not respond to top-posted replies, please don't ask
|
|
0
|
|
|
|
Reply
|
Victor
|
4/29/2010 12:06:15 PM
|
|
Guru <ashokjis@gmail.com> wrote:
> struct TIdCategory
> {
> string category;
> string id;
> };
>
> class CMyClass: public IMyClass
> {
> public :
> CMyClass(const string& id, const string category);
> virtual ~CMyClass();
> ....
> ....
> private :
> TIdCategory m_userCategory;
> ....
> };
>
> CMyClass::CMyClass(const string& id, const string category)
> {
> m_userCategory.id=id;
> m_userCategory.category=category; <---------------------- Here it
> giving Memory Leak by Purify
> }
>
>
> I am creating CMyClass object by new.
>
> 1) Why it is giving Memory Leak by Purify in string assigment ?
> 2) Is that really MLK?
> 3) If it is really MLK then in id assigment why it is not giving MLK?
There are no memory leaks in the code as you present it (unless you are
playing around with defines such that 'string' isn't really a standard
string or something like that.) It looks like Purify is giving you a
false positive. However, the tool could be flagging the code because of
the unnecessary extra copy construction.
You should ask the makers of the product or on a group/list devoted to
it.
|
|
0
|
|
|
|
Reply
|
Daniel
|
4/29/2010 1:04:26 PM
|
|
On Apr 29, 1:53=A0pm, Guru <ashok...@gmail.com> wrote:
> struct TIdCategory
> {
> =A0 =A0string category;
> =A0 =A0string id;
>
> };
>
> class CMyClass: public IMyClass
> {
> =A0 =A0 public :
> =A0 =A0 CMyClass(const string& id, const string category);
> =A0 =A0 virtual ~CMyClass();
> =A0 =A0 ....
> =A0 =A0 ....
> =A0 =A0 private :
> =A0 =A0 TIdCategory m_userCategory;
> =A0 =A0 ....
>
> };
>
> CMyClass::CMyClass(const string& id, const string category)
> {
> =A0 =A0m_userCategory.id=3Did;
> =A0 =A0m_userCategory.category=3Dcategory; =A0<---------------------- Her=
e it
> giving Memory Leak by Purify
>
> }
>
> I am creating CMyClass object by new.
^^^
Then there is your problem. Do you have to use new? If so, then do you
assign the resulting pointer to a smart pointer that takes care of the
delete? If not, then you will probably leak the CMyClass instance
sooner or later.
|
|
0
|
|
|
|
Reply
|
Gert
|
4/29/2010 1:19:10 PM
|
|
It was just typo.
Both are const string&
One more point , for 'id' also purify is giving MLK.
I found the for higher version of gcc GLIBCXX_FORCE_NEW flag is
available. But after using this flag also i am getting same result
|
|
0
|
|
|
|
Reply
|
Guru
|
4/29/2010 1:27:19 PM
|
|
"Guru" <ashokjis@gmail.com> wrote in message
news:fd50e647-a63d-4c76-bc61-ac7672ca8443@6g2000prg.googlegroups.com...
>
>
> It was just typo.
>
> Both are const string&
> One more point , for 'id' also purify is giving MLK.
>
>
> I found the for higher version of gcc GLIBCXX_FORCE_NEW flag is
> available. But after using this flag also i am getting same result
Stop saying MLK, it is a stupid non-acronym you have just made up.
/Leigh
|
|
0
|
|
|
|
Reply
|
Leigh
|
4/29/2010 1:35:37 PM
|
|
On 29.04.2010 15:27, * Guru:
>
>
> It was just typo.
Please quote what you're referring to.
> Both are const string&
Please always copy and paste code, avoiding human error.
Also, please post *complete* but minimal example of the problem.
Please see the FAQ item on how to ask about code that doesn't work.
> One more point , for 'id' also purify is giving MLK.
Please define your terms.
We are not telepaths.
> I found the for higher version of gcc GLIBCXX_FORCE_NEW flag is
> available. But after using this flag also i am getting same result
Presumably you have some silly error such as violating the law of three or
something. Perhaps you have copying defined in terms of assignment and have
forgotten to provide suitable copy constructor. Or something like that, or as
mentioned else-thread perhaps a false positive -- we can't know or even properly
guess from snippets of code that do not include the relevant stuff.
Cheers & hth.,
- Alf
|
|
0
|
|
|
|
Reply
|
Alf
|
4/29/2010 1:38:21 PM
|
|
On Apr 29, 9:27=A0am, Guru <ashok...@gmail.com> wrote:
> It was just typo.
>
> Both are const string&
> One more point , for 'id' also purify is giving MLK.
>
> I found the for higher version of gcc GLIBCXX_FORCE_NEW flag is
> available. But after using this flag also i am getting same result
As Gert-Jan de Vos already pointed out, you are leaking your CMyClass
object and therefore you are leaking all the sub-objects within it.
|
|
0
|
|
|
|
Reply
|
Daniel
|
4/29/2010 2:42:23 PM
|
|
|
7 Replies
481 Views
(page loaded in 0.117 seconds)
|