Article:
 |
|
What Is an Iterator in C++, Part 2
|
| Subject: |
|
Memory leak |
| Date: |
|
2008-08-17 12:47:22 |
| From: |
|
RoelAaij
|
|
|
|
Hi,
Great article, very clear and concise. I'll be using this to create my own container and iterators for it. One comment: you SQueue has a memory leak. Giving the Node a destructor fixes it:
~Node()
{
if (next_) delete next_;
}
|
Showing messages 1 through 1 of 1.
-
Memory leak
2008-08-17 13:32:56
RoelAaij
[View]
There are actually 2 memory leaks, this is how I fixed them without borking the queue:
I changed popFront into:
T popFront()
{
Node* p = root_;
T val = p->getVal();
root_ = root_->next_;
if(p) delete p;
return(val)
}
and the SQueue destructor into:
~SQueue()
{
while(root_) {
Node* p = root_;
root_ = root_->next_;
delete p;
}
}
Cheers, Roel