16
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【Unity】スタックトレースを有効にしてNativeArrayのメモリリークを探す

Last updated at Posted at 2020-10-16

ちょっと詰まったのでメモ。
UnityのバージョンはUnity2020.2.0a。

Job SystemでNativeArrayを使うスクリプトをオブジェクトに付けてゲームを再生すると次のようなエラーが出た。

A Native Collection has not been disposed, resulting in a memory leak. Enable Full StackTraces to get more details.

コンソールのメニューのStack Trace LoggingからすべてのスタックトレースをFullに変更した。image.png

しかしエラーの表記はさっきのまま変わらず詳細は表示されない。

#解決策
NativeArrayのスタックトレースはコンソールのメニューからいじれるものとは別らしい。NativeLeakDetection.ModeEnabledWithStackTraceに変更してやればよい。

SetupNativeLeakDetection.cs
using UnityEngine;
using Unity.Collections;

public class SetupNativeLeakDetection : MonoBehaviour
{
    void Start()
    {
        NativeLeakDetection.Mode = NativeLeakDetectionMode.EnabledWithStackTrace;
    }
}

エラー表示は次のようになった

A Native Collection has not been disposed, resulting in a memory leak. Allocated from:
Unity.Collections.NativeArray`1:.ctor(Int32, Allocator, NativeArrayOptions) (発生した関数名) (at (ソースのパス):(行数))

16
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
16
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?