Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Enter the 2020.2 Beta Sweepstakes for a chance to win an Oculus Quest 2.
    Dismiss Notice

Is there any callback from the SyncPoint for the NativeContainers in Jobs to dispose?

Discussion in 'Data Oriented Technology Stack' started by TMPxyz, Jul 15, 2019.

  1. TMPxyz


    Jul 20, 2012
    This must be a dumb question, but I cannot find out the place for NativeContainers to dispose.

    If I don't understand it in a wrong way, the jobs might outlast the OnUpdate() in System (if doesn't call Complete in main-thread), but they will finish at the sync points.

    The problem is [DeallocateOnJobCompletion] doesn't work for all NativeContainer, so I've to find a place to dispose those dangling container when they finally end.

    I've tried to find a callback on sync-point for system to do some mem cleanup but found nothing.

    So my backup plans include:
    • Use persistent alloc, so only clear() before use and dispose() at end. This is simple but it might hold the memory even the system doesn't run every frame.
    • Use Monobehaviour to expose an event for all systems to subscibe, which fire at the end of frame or some safe points.
    Is there some obvious solution I'm missing here. I really prefer some callback from sync-points.
  2. tertle


    Jan 25, 2011
    I'd say this is probably the standard approach.