Search Unity

[DeallocateOnJobCompletion] Clarification

Discussion in 'Entity Component System' started by Floofloof, Nov 26, 2018.

  1. Floofloof

    Floofloof

    Joined:
    Nov 21, 2016
    Posts:
    41
    Im trying to properly understand how to use this attribute [DeallocateOnJobCompletion]. Without knowing too much about it my gut understanding of it being used should be something like this.

    Code (CSharp):
    1.     public struct SomeJerb : IJob
    2.     {
    3.         [DeallocateOnJobCompletion]public NativeArray<int> someValues;
    4.         public void Execute()
    5.         {
    6.             //Some work on values
    7.         }
    8.     }
    And then when the job is done the NativeContainer is auto disabled. But that doesnt seem to wrok.

    If anyone has any better understanding of how this attribute is used im all ears. On a secondary note is there a way to dispose of a NativeContainer after a specific job? Say I have something like this

    Code (CSharp):
    1.     public class SomeSystem : JobComponentSystem
    2.     {
    3.         struct SomeJerb : IJob
    4.         {
    5.             [DeallocateOnJobCompletion] public NativeArray<int> someValues;
    6.             public void Execute()
    7.             {
    8.                 //Some work on values
    9.             }
    10.         }
    11.  
    12.         protected override JobHandle OnUpdate(JobHandle inputDeps)
    13.         {
    14.             //This NativeArray is never disposed of and I would prefer to not have
    15.             //a bunch or any NativeContainers that are persistant
    16.             //best way to deallocate?
    17.             NativeArray<int> myJerbvalues = new NativeArray<int>(100, Allocator.Temp);
    18.             var jerbHandle = new SomeJerb { }.Schedule(inputDeps);
    19.             return base.OnUpdate(jerbHandle);
    20.         }
    21.     }
    How would I dispose of the native array once the its no longer needed by a job?
     
  2. elcionap

    elcionap

    Joined:
    Jan 11, 2016
    Posts:
    138
    You forgot to set myJerbvalues to SomeJerb.someValues. Also, change the Allocator.Temp to Allocator.TempJob.

    []'s
     
  3. Floofloof

    Floofloof

    Joined:
    Nov 21, 2016
    Posts:
    41
    oh yea this was just a quick example i made up. Assuming it was wired correctly there are still issues