I have code that returns a reference to a member variable. The member variable is a vector of a certin class. This class consumes [tt]5848[/tt] or more bytes.
The process is like this, I loop on the number of objects in the [tt]vector[/tt] described above using [tt]iterator[/tt]s in a [tt]for()[/tt] loop. So I have a class like so:
Line [tt]05[/tt] above returns a reference to my member variable which is a [tt]vector[/tt].
I use this in a separate class:
I have observed that by using [tt]top[/tt] command on a UNIX platform, whenever the [tt]doIt()[/tt] function gets called, the resident memory usage keeps on increasing and increasing. It seems that the used memory for the [tt]vector[/tt] was not deleted.
Can anyone explain to me why? I am at a lost here since Rational Purify for UNIX did not report any memory leaks for this though as I said, through observation using [tt]top[/tt] command the [tt]RES[/tt] (resident memory) usage keeps on increasing. It does not decrease even after a call to [tt]erase()[/tt] on line [tt]13[/tt].
Some one help!
Rome did not create a great empire by having meetings, they did it by
killing all those who opposed them.
- janvier -
The process is like this, I loop on the number of objects in the [tt]vector[/tt] described above using [tt]iterator[/tt]s in a [tt]for()[/tt] loop. So I have a class like so:
Code:
01 class B; // consumes 5848 or more bytes
02 class A
03 {
04 public:
05 vector<B>& getB()
06 {
07 return myB;
08 }
09
10 void AddToList(B& b);
11 void RemoveFromList(B& b);
12 private:
13 vector<B> myB;
14 }
Line [tt]05[/tt] above returns a reference to my member variable which is a [tt]vector[/tt].
I use this in a separate class:
Code:
01 class A;
02 class MyMain
03 {
04 public:
05 void doIt()
06 {
07 vector<B>::iterator iter;
08 for(iter = myA.GetB().begin(); iter !=
09 myA.GetB().end;)
10 {
11 if(/* condition is to delete */)
12 {
13 iter = myA.GetB().erase(iter);
14 }
15 else
16 {
17 ++iter;
18 }
19 ...
21 ...
22 }
23 }
24 private:
25 A myA;
26}
I have observed that by using [tt]top[/tt] command on a UNIX platform, whenever the [tt]doIt()[/tt] function gets called, the resident memory usage keeps on increasing and increasing. It seems that the used memory for the [tt]vector[/tt] was not deleted.
Can anyone explain to me why? I am at a lost here since Rational Purify for UNIX did not report any memory leaks for this though as I said, through observation using [tt]top[/tt] command the [tt]RES[/tt] (resident memory) usage keeps on increasing. It does not decrease even after a call to [tt]erase()[/tt] on line [tt]13[/tt].
Some one help!
Rome did not create a great empire by having meetings, they did it by
killing all those who opposed them.
- janvier -