I wrote an object and destructor for said object that allocates an array on global memory. The problem is my deletion isn’t happening, which I can see because cudaMemGetInfo is saying I have the same amount of free memory before and after I call delete on the object. Here is what the code looks like. Can anyone spot what I could be doing wrong?
class myClass{
int* ptr2myDeviceArray;
public:
myClass(int size);
~myClass();
}
myClass::myClass(int size){
ptr2myDeviceArray = cudaMalloc( (void**)&ptr2myDeviceArray, size);
}
myClass::~myClass(){
cudaFree( (void**)&ptr2myDeviceArray );
}
int main(){
myClass* ptr2myClass = new myClass();
size_t freeMemBefore;
size_t totalMemBefore;
cudaMemGetInfo(&freeMemBefore, &totalMemBefore);
std::cout << freeMemBefore << std::endl;
delete ptr2myClass;
size_t freeMemAfter;
size_t totalMemAfter;
cudaMemGetInfo(&freeMemAfter, &totalMemAfter);
std::cout << freeMemAfter << std::endl;
return 0;
}
Freemem before and after prints out the exact same value.