Raistmer

Memory leak - why??

Discussion created by Raistmer on Jan 23, 2010
Latest reply on Mar 27, 2012 by rick.weber
With this code I had memory leak that eated all host memory in few minutes:

if(gpu_data)
clReleaseMemObject(gpu_data);

gpu_data = clCreateBuffer(context, CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR, fft_len*sizeof(float)*2, data, &err);
if(!gpu_data)
{
fprintf(stderr,"ERROR: clCreateBuffer failed, gpu_data\n");
}

and

if(gpu_chirps)
clReleaseMemObject(gpu_chirps);
gpu_chirps= clCreateBuffer(
context,
CL_MEM_READ_WRITE | CL_MEM_USE_HOST_PTR,
sizeof(fftwf_complex)*state.fft_len*state.dm_chunk_small,
chirp,
&err);
if(err != CL_SUCCESS)
{
fprintf(stderr,"Error: clCreateBuffer (gpu_chirp)\n");

}

And I have no memory leak when allocate them once and use write buffer:

err|=clEnqueueWriteBuffer(cq,gpu_data,CL_TRUE,0,fft_len*sizeof(float)*2,data,0,NULL,NULL);

clEnqueueWriteBuffer(cq,gpu_chirps,CL_TRUE,0,sizeof(fftwf_complex)*state.fft_len*state.dm_chunk_small,
chirp,0,NULL,NULL);

The question is:
why there was memory leak ?
buffers should be deleted before new allocation, right?

Outcomes