Michael schrieb:
Hi,
free() and delete are both used to release ptr memory. Any difference.
When shall I use which?
Simple rules:
- Memory allocated with malloc() has to be freed with free(),
- Objects that are new'ed have to be delete'd,
- Arrays of Objects, created with new[], must be destroyed with delete[].
Some guidelines:
- In C++, don't ever use malloc() or free(),
- Instead of new[] you are safer using a container (std::vector<for
example)
--
Thomas