Skip to content

Memory leak in OpenCL backend #2917

@laser101

Description

@laser101

I think I've discovered a memory leak in the OpenCL backend which occurs during a call to the array::device() method.

Specifically, in arrayfire/src/backend/opencl/api.cpp at line 7

namespace af {
template<>
AFAPI cl_mem *array::device() const {
    cl_mem *mem_ptr = new cl_mem;
    af_err err      = af_get_device_ptr((void **)mem_ptr, get());
    if (err != AF_SUCCESS)
        throw af::exception("Failed to get cl_mem from array object");
    return mem_ptr;
}
}  // namespace af

The allocation of a new cl_mem instance on the heap is not released, and the documentation does not indicate to the user that they need to call delete on the resulting pointer to release the resource. Subsequent calls to array::unlock() obviously don't release the resource either.

Apologies if I've misunderstood this (perhaps it is a reference counted resource?), but I would appreciate some clarification.

Many thanks.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions