trace memory free only when array owns memory

This commit is contained in:
Christopher Lackner 2021-04-07 09:58:53 +02:00
parent f8ca545455
commit daa0985a41

View File

@ -792,8 +792,9 @@ namespace ngcore
/// if responsible, deletes memory
NETGEN_INLINE ~Array()
{
delete [] mem_to_delete;
if(mem_to_delete)
mt.Free(sizeof(T)*allocsize);
delete [] mem_to_delete;
}
// Only provide this function if T is archivable
@ -847,8 +848,9 @@ namespace ngcore
/// assigns memory from local heap
NETGEN_INLINE const Array & Assign (size_t asize, LocalHeap & lh)
{
delete [] mem_to_delete;
if(mem_to_delete)
mt.Free(sizeof(T)*allocsize);
delete [] mem_to_delete;
size = allocsize = asize;
data = lh.Alloc<T> (asize);
mem_to_delete = nullptr;
@ -955,8 +957,9 @@ namespace ngcore
/// Deallocate memory
NETGEN_INLINE void DeleteAll ()
{
delete [] mem_to_delete;
if(mem_to_delete)
mt.Free(sizeof(T)*allocsize);
delete [] mem_to_delete;
mem_to_delete = NULL;
data = 0;
size = allocsize = 0;
@ -1108,8 +1111,9 @@ namespace ngcore
else
for (size_t i = 0; i < mins; i++) data[i] = std::move(hdata[i]);
#endif
delete [] mem_to_delete;
if(mem_to_delete)
mt.Free(sizeof(T) * allocsize);
delete [] mem_to_delete;
}
mem_to_delete = data;