Alex Rivera | Logout

Do I need to delete arrays explicitly in C++ for memory conservation?

Asked 2012-05-10T18:04:38.680
12

In one function. I create a local arrray. char arr[20]; And before end of this function. Will compiler do garbage collection for me? Or I need to do delete by myself?

Edit
Report

1 Answer

34

There is no Garbage Collection in C++.

However, if you use automatic variables, they will be destroyed when they fall out of scope.

As a rule, there should be 1 delete call for every new. If you have no new, you don't delete.

answered 2012-05-10T18:06:34.167

Your Answer