/// <summary> /// Disposes of this container and deallocates its memory immediately. /// </summary> public void Dispose() { CheckNotDisposed(); if (CollectionHelper.ShouldDeallocate(m_AllocatorLabel)) { #if ENABLE_UNITY_COLLECTIONS_CHECKS DisposeSentinel.Dispose(ref m_Safety, ref m_DisposeSentinel); #endif Memory.Unmanaged.Free(m_Data, m_AllocatorLabel); m_AllocatorLabel = Allocator.Invalid; } m_Data = null; }
public JobHandle Dispose(JobHandle inputDeps) { CheckNotDisposed(); if (CollectionHelper.ShouldDeallocate(m_AllocatorLabel)) { #if ENABLE_UNITY_COLLECTIONS_CHECKS // [DeallocateOnJobCompletion] is not supported, but we want the deallocation // to happen in a thread. DisposeSentinel needs to be cleared on main thread. // AtomicSafetyHandle can be destroyed after the job was scheduled (Job scheduling // will check that no jobs are writing to the container). DisposeSentinel.Clear(ref m_DisposeSentinel); #endif var jobHandle = new NativeReferenceDisposeJob { Data = new NativeReferenceDispose { m_Data = m_Data, m_AllocatorLabel = m_AllocatorLabel, #if ENABLE_UNITY_COLLECTIONS_CHECKS m_Safety = m_Safety #endif } }.Schedule(inputDeps); #if ENABLE_UNITY_COLLECTIONS_CHECKS AtomicSafetyHandle.Release(m_Safety); #endif m_Data = null; m_AllocatorLabel = Allocator.Invalid; return(jobHandle); } m_Data = null; return(inputDeps); }