Search Unity

Memory Leak with the simplest Job test ! Bug !?

Discussion in 'Entity Component System' started by Vagabond_, Aug 5, 2019.

  1. Vagabond_

    Vagabond_

    Joined:
    Aug 26, 2014
    Posts:
    1,148
    Hi i wanted to try implement some job based methods in a system and i decided to first give it a try.
    The first job i created i get the errors in the image. It seems to work based on the time it takes not sure if it's giving correct results. However i am wondering why are these warning showing and how bad are they.

    Here is super simple job. Am i doing something wrong !?

    Using Unity 2018.3.11f1
    EDIT : also using latest jobs, burst etc packages

    upload_2019-8-5_7-28-22.png

    Code (CSharp):
    1.  
    2. using UnityEngine;
    3. using Unity.Jobs;
    4. using Unity.Burst;
    5. using Unity.Mathematics;
    6.  
    7. public class MT_Test : MonoBehaviour
    8. {
    9.     [BurstCompile]
    10.     struct Test_01_Job : IJob
    11.     {
    12.         public int iters;
    13.         public int vecsCount;
    14.  
    15.         public void Execute()
    16.         {
    17.             for (int j = 0; j < iters; j++)
    18.             {
    19.                 for (int i = 0; i < vecsCount; i++)
    20.                 {
    21.                     math.cross(new float3(1.0f), new float3(1.0f));
    22.                 }
    23.             }
    24.         }
    25.     }
    26.  
    27.     [SerializeField] int iterations = 100;
    28.     [SerializeField] int vecsCount = 1000000;
    29.  
    30.     /// <summary>
    31.     ///
    32.     /// </summary>
    33.     void Update()
    34.     {
    35.         if(Input.GetMouseButtonDown(0))
    36.         {
    37.             float t = Time.realtimeSinceStartup;
    38.             Test_01_MT();
    39.             Debug.Log(Time.realtimeSinceStartup - t);
    40.         }
    41.     }
    42.  
    43.     void Test_01_MT()
    44.     {
    45.         Debug.Log("Test 01 MT");
    46.  
    47.         Test_01_Job job = new Test_01_Job
    48.         {
    49.             iters = iterations,
    50.             vecsCount = vecsCount
    51.         };
    52.         JobHandle handle = new JobHandle();
    53.         job.Schedule(handle);
    54.         handle.Complete();
    55.     }
    56. }
    57.  
    58.  
     
    Last edited: Aug 5, 2019
  2. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,759
    Code (CSharp):
    1.         JobHandle handle = new JobHandle();
    2.         job.Schedule(handle);
    3.         handle.Complete();
    You're completing the wrong handle

    It should just look like this

    Code (CSharp):
    1.         var handle = job.Schedule();
    2.         handle.Complete();
     
  3. Vagabond_

    Vagabond_

    Joined:
    Aug 26, 2014
    Posts:
    1,148
    No comment :D
    Thanks a lot !