Memory Leak in NdArray
jzylkin opened this issue · comments
jzylkin commented
Describe the bug
The NdArray<> class can allocate memory to create the underlying _array
using std:allocator, but its destructor does not deallocate this memory.
To Reproduce
Steps to reproduce the behavior:
- Create an NdArray object on the stack using the constructor that takes a size and shape.
- Observe that memory is allocated on the heap for this array.
- After the NdArray object goes out of scope, the memory is not freed.
Expected behavior
I expect the NdArray object to clean up the memory it creates when it is destroyed.
David Pilger commented
Not sure what you are talking about? The NdArray
destructor calls deleteArray()
which deallocates the heap memory.
void deleteArray() noexcept
{
if (ownsPtr_ && array_ != nullptr)
{
allocator_.deallocate(array_, size_);
}
array_ = nullptr;
shape_.rows = shape_.cols = 0;
size_ = 0;
ownsPtr_ = false;
endianess_ = Endian::NATIVE;
}
jzylkin commented
Hi David,
I was looking at an older release from this February. I did not realize you
fixed this already. Thanks for getting back to me!
Jack
…On Thu, Dec 7, 2023 at 4:11 PM David Pilger ***@***.***> wrote:
Not sure what you are talking about? The NdArray destructor calls
deleteArray() which deallocates the heap memory.
void deleteArray() noexcept
{
if (ownsPtr_ && array_ != nullptr)
{
allocator_.deallocate(array_, size_);
}
array_ = nullptr;
shape_.rows = shape_.cols = 0;
size_ = 0;
ownsPtr_ = false;
endianess_ = Endian::NATIVE;
}
—
Reply to this email directly, view it on GitHub
<#207 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABKIXJCEUAOWRKQL4DAFNL3YIJLMFAVCNFSM6AAAAABALYLX52VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNBWGI4TQMBXGU>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>