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