0

I have the following cuda c++. I am trying to delete the h_c, h_c_Row and h_c_ColdIndices array using delete function. But the memory is not getting deleted when I see the memory and the value stored in that memory for each array in the debug mode in nsight eclispe.

    float *h_c = new float[nnz_c];
    int *h_c_Row = new int[n_k+1];
    int *h_c_ColIndices = new int[nnz_c];
    create_sparse_MY(c,n_k,d,h_c,h_c_Row,h_c_ColIndices, nnz_c);

    // transfer sparse c to device memory
    float *d_sc;  (cudaMalloc(&d_sc, nnz_c * sizeof(float)));
    (cudaMemcpy(d_sc, h_c, (nnz_c) * sizeof(float), cudaMemcpyHostToDevice));
    int *d_c_ColIndices; (cudaMalloc(&d_c_ColIndices, nnz_c * sizeof(*d_c_ColIndices)));
    (cudaMemcpy(d_c_ColIndices, h_c_ColIndices, (nnz_c) * sizeof(int), cudaMemcpyHostToDevice));
    int *d_c_RowIndices;  (cudaMalloc(&d_c_RowIndices, (n_k+1) * sizeof(*d_c_RowIndices)));
    (cudaMemcpy(d_c_RowIndices, h_c_Row, (n_k+1) * sizeof(int), cudaMemcpyHostToDevice));
     delete[] h_c;
     delete[] h_c_Row;
     delete[] h_c_ColIndices

Can someone please help me with it? Is this the right way to delete to arrays in main memory in cuda c++?

newbie
  • 443
  • 1
  • 4
  • 14

1 Answers1

1

Memory being released is not the same as memory losing its previous content immediately.

deleteing a pointer to an object (or array) calls the objects (plural for arrays) destructor, and makes the memory manager reclaim the memory. In the case of built-in types, the destrcutor does nothing (the memory content doesn't change), but the memory is reclaimed.

StoryTeller - Unslander Monica
  • 165,132
  • 21
  • 377
  • 458