C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Where is the memory leak

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
Aditya Pandit
Guest





PostPosted: Wed May 17, 2006 10:21 am    Post subject: Where is the memory leak Reply with quote



--------Sample code begin------
typedef boost::shared_ptr<SomeClass> SomePtr;
typedef std::vector<SomePtr> vSomePtr;

ClassA {
public:
vSomePtr methodA( ); //returns a vector of shared_ptrs
}

classB::methodB //processes a vector of smart_ptrs
{
.........
vSomePtr vTmp(pClassA->methodA()) ; //boundschecker shows a
memory leak here
//process the vector
vTmp.clear( );
...........
}
--------Sample code end------
Boundschecker shows a memory leak in the above statement
I have tried the following
a)assignment(this was what I was doing initially)
vTmp = pClassA->methodA()
b) swap(then I tried swapping hoping it will clear the returned
vector)
vSomePtr vTmp;
vTmp.clear( );
vTmp.swap(pClassA->methodA( ) );
---------
but it shows a memory leak in both the above cases.

Let me know if there is a safer way to copy/assign a vector of smart
pointers being returned by a method. I am not able to figure out what
is causing that leak.


Thanks,
Adi


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Ulrich Eckhardt
Guest





PostPosted: Wed May 17, 2006 3:21 pm    Post subject: Re: Where is the memory leak Reply with quote



Aditya Pandit wrote:
Quote:
typedef boost::shared_ptr<SomeClass> SomePtr;
typedef std::vector<SomePtr> vSomePtr;

ClassA {
public:
vSomePtr methodA( ); //returns a vector of shared_ptrs
}

classB::methodB //processes a vector of smart_ptrs
{
.........
vSomePtr vTmp(pClassA->methodA()) ; //boundschecker shows a
memory leak here
//process the vector
vTmp.clear( );
...........
}

There is no memleak in above code, provided you did not hit a bug in
either
Boost, your standardlibrary or your compiler.

Quote:
Boundschecker shows a memory leak in the above statement

What exactly does it claim is leaking? Parts of the vector, parts of the
contained shared_ptrs or parts of what they point to? Also, what
version of
Boost are we talking about and what compiler/stdlib are you using?

Uli


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Allan W
Guest





PostPosted: Wed May 17, 2006 10:21 pm    Post subject: Re: Where is the memory leak Reply with quote



Ulrich Eckhardt wrote:
Quote:
There is no memleak in above code, provided you did not hit a bug in
either
Boost, your standardlibrary or your compiler.

Or conceivably in Bounds Checker.

Try putting the "memory leak" statement in a loop, execute it 100
times.
Do you have 100 times as much memory loss?
If not, then something else is really going on.


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.