Click here to Skip to main content
15,885,309 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I try use the vector problem as same:
C++
typedef std::tr1::shared_ptr<ABCD> DEFABCD;
std::vector<DEFABCD*> student_marks;

addvecter()
{
       // demo I add 200 item
for(int i = 0 ; i < 200 ;i ++)
{
DEFABCD *a = new DEFABCD();
student_marks.push_back(a);
}
}

//After insert the memory  in task manager increase (EX: 1700 -> 1800)
//after that i call delete function

deletevector()
{
    while (!student_marks.empty())
   {
       delete student_marks.back();
       student_marks.pop_back();
   }
   student_marks.clear();
}

the memory in task manager then not reduce.
How can I delete to reduce memory (1800 -> 1700)?

P/S: I uses Cobjectarray with same problem.
Posted
Updated 26-Nov-10 17:51pm
v2

1 solution

What you're seeing isn't a memory leak, it's just the working set of the process changing. Unfortunately what task manager calls memory is just the private working set of the process and not showing you what you think you're seeing.

Now, a far bigger problem. Why on earth are you using pointers to shared pointers? If that doesn't confuse you (or people maintaining your code after you) then nothing will. You're probably not doing what you think you're doing (whatever that is).

So you can make your code a lot simpler by eliminating the shared_ptrs AND just using values in your vector. Unless of course ABCD is an interface class in which case keep it but get rid of all the manual memory management rubbish (apart from the new). Something like:

std::vector<abcd> foo;

void populate_vector()
{
    foo = std::vector<abcd>( 200 );
}

void delete_vector()
{
    foo.clear();
}


Cheers,

Ash
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900