---
title: プレイヤーでのメモリカウンターへのアクセス
product: Unity Editor
version: '6000.0'
latest_version: '7000.0'
status: This page documents version 6000.0. The latest version is 7000.0.
canonical: https://docs.unity.com/ja-jp/engine/6000.0/manual/analysis/profiler/visualizing-data/memory/counters-players
latest_url: https://docs.unity.com/ja-jp/engine/7000.0/manual/analysis/profiler/visualizing-data/memory/counters-players.md
last_updated: 2026-10-30
generated_at: 2026-11-16T19:34:59.958Z
locale: ja-jp
---

# プレイヤーでのメモリカウンターへのアクセス

> ビルドされたプレイヤーのメモリメトリクスをディスプレイします。

[ProfilerRecorder API](/engine/6000.0/script-reference/unity/profiling/profilerrecorder.md) を使用して、プレイヤーの Memory Profiler モジュールのカウンターにアクセスできます。

以下の例は、**合計予約さ**れたメモリ、**GC 予約**されたメモリ、および**システム使用メモリ**のメトリクスを収集し、[`GUI.TextArea`](/engine/6000.0/script-reference/unityengine/gui/textarea.md)として表示する簡単なスクリプトを示しています。Memory Profiler モジュール情報は、[`ProfilerCategory.Memory`](/engine/6000.0/script-reference/unity/profiling/profilercategory/memory.md) プロファイラーカテゴリに属します。

```language-csharp
using System.Text;
using Unity.Profiling;
using UnityEngine;

public class MemoryStatsScript :MonoBehaviour
{
    string statsText;
    ProfilerRecorder totalReservedMemoryRecorder;
    ProfilerRecorder gcReservedMemoryRecorder;
    ProfilerRecorder systemUsedMemoryRecorder;

    void OnEnable()
    {
        totalReservedMemoryRecorder = ProfilerRecorder.StartNew(ProfilerCategory.Memory, "Total Reserved Memory");
        gcReservedMemoryRecorder = ProfilerRecorder.StartNew(ProfilerCategory.Memory, "GC Reserved Memory");
        systemUsedMemoryRecorder = ProfilerRecorder.StartNew(ProfilerCategory.Memory, "System Used Memory");
    }

    void OnDisable()
    {
        totalReservedMemoryRecorder.Dispose();
        gcReservedMemoryRecorder.Dispose();
        systemUsedMemoryRecorder.Dispose();
    }

    void Update()
    {
        var sb = new StringBuilder(500);
        if (totalReservedMemoryRecorder.Valid)
            sb.AppendLine($"Total Reserved Memory: {totalReservedMemoryRecorder.LastValue}");
        if (gcReservedMemoryRecorder.Valid)
            sb.AppendLine($"GC Reserved Memory: {gcReservedMemoryRecorder.LastValue}");
        if (systemUsedMemoryRecorder.Valid)
            sb.AppendLine($"System Used Memory: {systemUsedMemoryRecorder.LastValue}");
        statsText = sb.ToString();
    }

    void OnGUI()
    {
        GUI.TextArea(new Rect(10, 30, 250, 50), statsText);
    }
}
```

以下のスクリーンショットは、[Tanks！ チュートリアルプロジェクト](https://assetstore.unity.com/packages/essentials/tutorial-projects/tanks-tutorial-46209)にスクリプトを追加した結果を示しています。


**Tanks! tutorial with the overlaid memory information:**
![](/api/media?file=/engine/6000.0/media/images/profiler-tanks-memory-overlay.png)

この情報は、Memory Profiler モジュールで使用可能な他の[高レベルカウンタ](/engine/6000.0/manual/analysis/profiler/visualizing-data/memory/memory.md)と同様に、リリースプレイヤーで使用できます。カスタムモジュールで選択したメモリーカウンターをプロファイラーウィンドウに表示するには、[プロファイラーモジュールエディタ](/engine/6000.0/manual/analysis/profiler/customizing/creating-custom-modules/module-editor.md)を使用してチャートを設定します。

コードにプロファイラー情報を追加する方法の詳細については、[プロファイリング情報の追加](/engine/6000.0/manual/analysis/profiler/customizing/adding-information-code.md) を参照してください。

## 追加リソース##additional-resources

* [プロファイラーカウンターリファレンス](/engine/6000.0/manual/analysis/profiler/counters-reference.md)
* [コードへのプロファイリング情報の追加](/engine/6000.0/manual/analysis/profiler/customizing/adding-information-code.md)
* [プロファイラーカウンターの可視化](/engine/6000.0/manual/analysis/profiler/customizing/adding-information-code/creating-custom-counters.md)
* [Memory Profiler モジュールリファレンス](/engine/6000.0/manual/analysis/profiler/visualizing-data/memory/memory.md)
