A small problem about delete in CPP

Do you need to manually delete a pointer defined in the

CPP function (not the main function) at the end of the function? Or will the system automatically delete?
as at the end of this code, is that delete redundant?

void mergeArray(int * & A, int low, int high)
{
    int cnt = 0;
    int * B = new int[high - low + 1];
    int mid = low + (high - low) / 2;
    int i = low;
    int j = mid + 1;
    while( mid + 1 > i && high + 1 > j ) {
        if ( A[i] < A[j] )    B[cntPP] = A[iPP];
        else    B[cntPP] = A[jPP];
    }
    while( mid + 1 > i )    B[cntPP] = A[iPP];
    while( high + 1 > j )    B[cntPP] = A[jPP];
//    A:loop from low, B:loop from 0 
    for ( i = low, cnt = 0; i < high + 1; iPP )    A[i] = B[cntPP];
    delete[] B;
}
CPP
Mar.06,2021

new opens memory on the heap. Unless the whole process ends, it will be reclaimed by the operating system. Otherwise, the variables in memory are still there after the end of the function

.
Menu