I see in C++ there are multiple ways to allocate and free data and I understand that when you call malloc you should call free and when you use the
malloc
free
Use malloc and free only for allocating memory that is going to be managed by c-centric libraries and APIs. Use new and delete (and the [] variants) for everything that you control.
new
delete
[]