Oleg
Thu Apr 21 06:21:20 CDT 2005
> > Now check the memory location of var.bstrVal. string's contents are
> > still written at its location. which is wastage of memory. I think
> > memory should be free of var.bstrVal now. because var has been
> > cleared.
>
> The typical strategy for freeing a particular piece of heap space is simply
> to mark it as free in the internal heap administration structures. There is
> no need to explicitly overwrite the heap /data/. So, your observation
> gives no indication that the memory has not been freed.
When the application is running under debugger, or linked with Debug CRT,
the freed heap block is usually overwritten with a pattern that helps
to detect reuse-after-delete situations (unless special actions are taken
to disable such behavior).
In case of BSTR allocation, there is an additional cache involved, so it is possible
that the heap block is not freed when BSTR is released:
http://support.microsoft.com/?id=139071
Regards,
Oleg
[VC++ MVP]