loosing memory, not knowing how

I have a -small?- issue with one of my own made programs.

I do not know how I am loosing memory, where it goes? That is a mystery…

It seems like one of my frees instructions is not working as it is suppose to.

The code does something like this:

[codebox]

cudaArray* cuArrayTarget = 0;

cudaArray* cuArrayReference = 0;

cudaMallocArray(&cuArrayReference, &channelDesc, width, height);

cudaMemcpyToArray(cuArrayReference, 0, 0, refImage, widthheightsizeof(float), cudaMemcpyHostToDevice);

cudaBindTextureToArray(textReference, cuArrayReference, channelDesc);

cudaMallocArray(&cuArrayTarget, &channelDesc, width, height);

cudaMemcpyToArray(cuArrayTarget, 0, 0, refImage, widthheightsizeof(float), cudaMemcpyHostToDevice);

cudaBindTextureToArray(textTarget, cuArrayTarget, channelDesc);

int* v1;

int* v2;

cudaMalloc((void**)&v1, s1*sizeof(int));

cudaMalloc((void**)&v2, s2*sizeof(int));

kernel …

int* output = (int*)malloc( v3*sizeof(int) );

cudaMemcpy(output, v1, v3*sizeof(int), cudaMemcpyDeviceToHost);

cudaUnbindTexture(textReference);

cudaUnbindTexture(textTarget);

cudaFree(values);

cudaFree(vectors);

cudaFreeArray(cuArrayReference);

cudaFreeArray(cuArrayTarget);

free(output);

[/codebox]

As you can see I do create 2 cudaArrays, allocate 2 arrays, update 2 textures, copy back the info.

There are no errors on the cudaFree or cudaUnbinds (the CUDA_SAFE_CALL has been removed to make the code more looking-friendly).

Any idea where my leak can be?

Hi,

you also allocate:

int* v1;
int* v2;

cudaMalloc((void**)&v1, s1sizeof(int));
cudaMalloc((void**)&v2, s2
sizeof(int));

and you forget to free them, probably you try to free them by:

cudaFree(values);
cudaFree(vectors);

However then you allocate you use v1 and v2.

Happy coding!