Search Unity

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

    TMPxyz

    Joined:
    Jul 20, 2012
    Posts:
    765
    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

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    1,671
    I'd say this is probably the standard approach.