Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Extrem RAM usage with NativeMultiHashMap and NativeArray

Discussion in 'Entity Component System' started by schneckerstein, Apr 24, 2019.

  1. schneckerstein

    schneckerstein

    Joined:
    Dec 6, 2018
    Posts:
    36
    I'm currently jobifying a custom Tool that splits +300K geometry into handable chunks.
    However as soon as I start the process, my RAM ussage blows up quickly beyond my systems capacity (16gb). Im having a NativeMultiHashMap<int, int> and a NativeArray<float3>, both with a capacity of ~300.000 elements. The HashMap is filled with data by a IJobForParallel.

    The plain C# never had any issues like that.

    Any Ideas?
     
  2. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    One guess. Your code has a bug where it's creating way more then 300k entries in NativeMultiHashMap. HashMaps have this undocumented feature where they auto expand if needed doubling the current capacity every time they exceed their current capacity.
     
  3. schneckerstein

    schneckerstein

    Joined:
    Dec 6, 2018
    Posts:
    36
    I tried reducing the initial capacity, but I'm getting System.Exceptions that the hashmap is not large enough. :(

    Other guesses I can't check on right now:
    • Dispose() is somewhat not executed immediately
    • Each new Key causes the NativeMultiHashMap to double it's size
     
  4. schneckerstein

    schneckerstein

    Joined:
    Dec 6, 2018
    Posts:
    36
    I've switched to a permanent allocation now to at least avoid the possibliy of the first one. Also I modified my Job to emit always the same hash -> still memory issues.

    Since the pure creation of the Job causes these issues, I'm sure now that NativeHashMap<>.Concurrent causes some kind of "garbage" thats is not cleaned. Since this struct doesn't implement something like .Dispose() I'm in a dead end now. :(
     
  5. Piefayth

    Piefayth

    Joined:
    Feb 7, 2017
    Posts:
    61
    Does this only happen in the editor, or in a standalone build too? If build works OK it might be the native collection safety checks; they do some allocations.
     
  6. schneckerstein

    schneckerstein

    Joined:
    Dec 6, 2018
    Posts:
    36
    Disabled Safety Check, still no luck. It's a editor only tool btw.
     
  7. schneckerstein

    schneckerstein

    Joined:
    Dec 6, 2018
    Posts:
    36
    Any ideas? Like I said: the culprit is the NativeHashMap<>.Concurrent causing undisposable garbage.
     
  8. sngdan

    sngdan

    Joined:
    Feb 7, 2014
    Posts:
    1,131
    I have worked extensively with NMHM in previous ECS versions without allocation issues (but moved to dynamic buffers for speed reasons in my case)

    Would you be able to show a code example that replicates the issue.