Board index » cppbuilder » ListView->Items->Clear() question.

ListView->Items->Clear() question.

Does
ListView1->Items->Clear();
also delete the user defined Data for each Item.?
I would hope it does - but I'm not sure and I don't
to leave a lot of  unused memory laying around.
 

Re:ListView->Items->Clear() question.


Quote
Larry W Powell wrote:

> Does
> ListView1->Items->Clear();
> also delete the user defined Data for each Item.?
> I would hope it does - but I'm not sure and I don't
> to leave a lot of  unused memory laying around.

Actually the answer is quite obvious, it doesn't. Their are
several reasons:
1. the data might not have been allocated using new in which
case a delete would fail.
2. the data might be referenced multiple times in which case
deleting it would cause the other reference to become invalid
3. You could have stored in int in the void*
4. You should cast the void* to the correct (base) type before
deleting it. Otherwise the destructor might not be called
potentionally causing a memory leak.

Regards,
Eelke

Other Threads