Search Unity

Question NativeList Caching and Disposing

Discussion in 'Entity Component System' started by Bodyclock, Sep 28, 2020.

  1. Bodyclock

    Bodyclock

    Joined:
    May 8, 2018
    Posts:
    172
    Hi All, I have a procedural mesh generation system that asynchronously caches VertexData structs and Indices into NativeLists through the Job system and a compute shader. I then use that cache to generates per frame frustum culled meshes. The cache can be regenerated anywhere between every 5 frames to 50+ frames. This all works fantastically well and the performance is great (Burst is a beast).
    The question I have is it safe to use the NativeLists as a data cache. They are Disposed of OnDestroy and this doesn't seem to pose an issue. But every time I regenerate the cache I get the usual, A Native Collection has not been disposed, resulting in a memory leak, in the Console.
    Is this an issue?
    Cheers
     
    bb8_1 likes this.
  2. Bodyclock

    Bodyclock

    Joined:
    May 8, 2018
    Posts:
    172
    Ok, In writing the question and going the the logic I answered my own question. While I have the Job cached I still need to Dispose of the NativeLists every regeneration.
    Sorry for making you look. :)
     
    bb8_1 likes this.