Re: resizable array of pointers
"Mark" <mnbayazit@gmai l.comwrote in message
news:1160102057 .156398.52090@i 42g2000cwa.goog legroups.com...
that
>
okay, that worked like a charm!
>
now..last question..i hope.
>
i've got my destructor
>
ObStash::~ObSta sh()
{
delete [] storage;
}
>
but will that be sufficient to prevent leakage?
Not if the objects pointed to were created with 'new'.
Yes, and to the correct type of pointer as well (the same type created with 'new').
Yes it is.
No they won't. If they were created with 'new' they consume space in the free store like anything
else until they are explicitly deleted.
A related story.
Yes, as part of the destruction of the Student.
No, it shouldn't. It can't know the types really being pointed to by the array elements, and it
can't know whether those objects were created with 'new'.
Yes.
No.
DW
"Mark" <mnbayazit@gmai l.comwrote in message
news:1160102057 .156398.52090@i 42g2000cwa.goog legroups.com...
David W wrote:
My guess is that the numbers you are putting in there no longer exist, but you didn't include
My guess is that the numbers you are putting in there no longer exist, but you didn't include
code. If the ints are ordinary local variables they may have gone out of scope. You may need to
create each int to be stored with 'new' if that's the case (and delete later).
create each int to be stored with 'new' if that's the case (and delete later).
okay, that worked like a charm!
>
now..last question..i hope.
>
i've got my destructor
>
ObStash::~ObSta sh()
{
delete [] storage;
}
>
but will that be sufficient to prevent leakage?
since it's an array of pointers. i figure i would have to delete each
pointer first,
pointer first,
and then delete the array, since it's declared as void
**storage, however.. i can't delete each pointer because they delete
void* is undefined!
>
but, from my understanding, it's not necessarily delete integers
anyways..
**storage, however.. i can't delete each pointer because they delete
void* is undefined!
>
but, from my understanding, it's not necessarily delete integers
anyways..
they'll take care of themselves..
else until they are explicitly deleted.
but the Student class
however, is another story.
however, is another story.
class Student
{
string name;
ObStash scores;
>
public:
Student(string name);
void print();
void cleanUp();
};
>
the string has it's own destructor i believe, and should clean up after
it's self...
{
string name;
ObStash scores;
>
public:
Student(string name);
void print();
void cleanUp();
};
>
the string has it's own destructor i believe, and should clean up after
it's self...
the obstash's destructor should clean up the scores too i think..
can't know whether those objects were created with 'new'.
but what about when
>
ObStash students;
>
goes out of scope?
>
do i need to call the destructor for each object individually or
anything..? (delete each student manually)
>
ObStash students;
>
goes out of scope?
>
do i need to call the destructor for each object individually or
anything..? (delete each student manually)
or..will they all die
gracefully?
gracefully?
DW
Comment