The Memory Advice API beta is now deprecated, and no longer recommended for use.
Memory Advice API の概要
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
Memory Advice API は、Android アプリがメモリ使用量のセーフティ リミットを超えないようにする、試験運用版のネイティブ API です。そのためこの API は、使用中のメモリリソースの量を推定し、特定のしきい値を超えたときにアプリに通知します。また、メモリ使用率の推定値をアプリに直接報告することもできます。
API が提供する推定値は、アプリでメモリ使用量を調整すべきタイミングを判断したり、アプリの今後のバージョンで改善すべき部分を見つけたりするのに役立ちます。調整には、映像と音声のアセットのディテールや品質を下げるなど、メモリ使用量を変更するあらゆるものが含まれます。
メモリリソースの推定値には、malloc によって割り当てられたネイティブ ヒープメモリと、OpenGL ES API と Vulkan Graphics API によって割り当てられたグラフィック メモリが含まれているため、Memory Advice API はゲームやグラフィックを多用するアプリに最適です。
推定は次のものに基づいて行われます。
- API によって収集されるデバイス指標
- デバイスからの機械学習データ
- デバイスのテスト
Memory Advice API は、API レベルで一連のメモリ アドバイス状態を定義し、いくつかの関数を通じてアプリに通知します。
スタートガイド
Unity ゲーム用スタートガイド
配信
Memory Advice API は Android Game Development Kit(AGDK)に含まれており、次のチャネルを介して配信されます。
ゲームは、ビルド環境ごとに推奨される Memory Advice API リリースを使用する必要があります。Android Studio の場合は Jetpack リリースが推奨されます。Android Game Development Extension(AGDE)の場合は、AGDK ダウンロード ページにあるリリースが推奨されます。
機能
このセクションでは、Memory Advice API の機能について説明します。
メモリの状態
この API がアプリに報告するメモリ状態は次のとおりです。
- MEMORYADVICE_STATE_OK
- MEMORYADVICE_STATE_APPROACHING_LIMIT
- MEMORYADVICE_STATE_CRITICAL
詳細については、memoryadvice_memorystate のリファレンス ページをご覧ください。
メモリ状態の報告
この API は、ポーリング、コールバックのいずれかのメカニズムを使用してメモリ状態を報告できます。
ポーリング:
アプリは任意のタイミングでこの API を呼び出してメモリ状態を取得できます。
コールバック:
アプリはコールバック関数を Memory Advice API に登録できます。その場合、コールバックの呼び出し頻度を指定します。API はこの頻度に基づいて、アプリのメモリの状態が安全な範囲の上限に近づいた、またはひっ迫した場合にコールバックを実行するタイミングを決定します。メモリの状態が安全な場合は、コールバックは呼び出されません。コールバックは、アプリのスレッドからではなく、コールバック独自のスレッドから実行されます。
コストと呼び出し頻度に関する考慮事項
Memory Advice API がメモリ状態を生成するには、コンピュータの処理時間がかかります。そのコストはデバイスによって異なりますが、通常は 1 回の呼び出しあたり 1 ~ 3 ミリ秒です。メモリ状態のポーリング頻度や、メモリ状態コールバックに指定する頻度を決定する際には、このオーバーヘッドを考慮する必要があります。
要件
デバイスの要件
- Android 4.4(API レベル 19)以降
アプリの要件
NDK バージョンの要件
この Memory Advice API リリースは、一般的な NDK のほとんどのバージョンをサポートしています。サポートされている NDK については、リリースノートをご覧ください。
参考情報
問題とフィードバック
Memory Advice API はベータ版であり、皆様からのフィードバックをお待ちしております。この API のご使用中に生じたご提案や問題につきましては、IssueTracker で問題を作成してお知らせください。
このページのコンテンツやコードサンプルは、コンテンツ ライセンスに記載のライセンスに従います。Java および OpenJDK は Oracle および関連会社の商標または登録商標です。
最終更新日 2025-08-26 UTC。
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["必要な情報がない","missingTheInformationINeed","thumb-down"],["複雑すぎる / 手順が多すぎる","tooComplicatedTooManySteps","thumb-down"],["最新ではない","outOfDate","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["サンプル / コードに問題がある","samplesCodeIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-08-26 UTC。"],[],[],null,["| **Note:** The Memory Advice API Beta is now over and the library is deprecated. [learn more about alternative memory management approaches](/games/optimize/memory-allocation).\n\nThe Memory Advice API is an experimental native API that\nhelps Android apps stay within safety limits for memory use. The API\nachieves this by estimating the amount of memory resources that are in use, and\nthen notifying the app when certain thresholds are exceeded. The API can\nalso report the estimated percentage of memory use directly to your app.\n\nThe estimations provided by the API help to determine when your app should\nadjust its memory use, or to find areas to improve in future versions of your\napp. The adjustments could include anything that changes memory consumption, such\nas lowering the details and quality of visual and audio assets.\n\nThe estimated memory resources include native heap memory allocated by malloc,\nand graphics memory allocated by the OpenGL ES and Vulkan Graphics APIs making\nthe Memory Advice API ideal for games and graphic intensive apps.\n\nThe estimates are made based on the following:\n\n- Device metrics collected by the API\n- Machine learning data from devices\n- Device testing\n\nAt the API level, the Memory Advice API defines a set of memory\nadvice states and communicates them to apps with a set of functions.\n\n[Get Started](/games/sdk/memory-advice/start)\n[Get Started for Unity games](/games/engines/unity/memory-advice)\n\nDistributions\n\nThe Memory Advice API is a part of the Android Games Development\nKit (AGDK) and is distributed through the following channels:\n\n- Binary releases in the [Android Games Jetpack libraries](/jetpack/androidx/releases/games).\n- Binary releases on the [AGDK download page](/games/agdk/get-agdk#agdk-libraries).\n- Source code on [AOSP](https://android.googlesource.com/platform/frameworks/opt/gamesdk/+/refs/heads/master/test/memoryadvice).\n\nGames should use the Memory Advice API release that is\nrecommended for their build environment. For Android Studio, we recommend the\nJetpack release. For the [Android Game Development Extension](/games/agde)\n(AGDE), we recommend the release on the AGDK download page.\n\nFeatures\n\nThis section describes the Memory Advice API features.\n\nMemory state\n\nThe API reports the following memory states to apps:\n\n- MEMORYADVICE_STATE_OK\n- MEMORYADVICE_STATE_APPROACHING_LIMIT\n- MEMORYADVICE_STATE_CRITICAL\n\nFor details, see the [memoryadvice_memorystate](/reference/games/memory-advice/group/memory-advice#memoryadvice_memorystate) reference pages.\n\nReporting the memory state\n\nThe API supports reporting the memory state through either a polling or a callback mechanism:\n\n- **Polling** : \n\n An app can call the API at any time to retrieve the memory state.\n\n- **Callback** : \n\n An app can register a callback function with the Memory Advice API.\n The app specifies the calling frequency for the callback. The API\n uses the frequency to determine when to execute the callback when the application memory\n condition is approaching the safe limit or is critically low. The callback is not invoked\n if the memory condition is safe. The callback is executed from its own thread,\n not from a thread belonging to the app.\n\nCost and calling frequency considerations\n\nThe Memory Advice API uses computational time to generate\nthe memory status. The cost varies by device, but is usually between 1ms and 3ms\nper call. You should consider this overhead when determining how often\nto poll the memory state, or what frequency to specify for the memory state callback.\n\nRequirements\n\n**Device requirements**\n\n- Android 4.4 (API level 19) or higher.\n\n**App requirements**\n\n- The API only supports native apps (apps primarily written in C/C++).\n\n- The API only supports physical devices; emulators are not supported.\n\n**NDK version requirements**\n\nThe Memory Advice API release supports most popular NDK versions,\nrefer to the [release notes](https://developer.android.com/jetpack/androidx/releases/games)\nfor the supported NDK list.\n| **Note:** Addition versions of the NDK are supported by [the full AGDK library](/games/agdk/get-agdk#agdk-libraries).\n\nAdditional Resources\n\n- [Memory Advice API release notes](https://developer.android.com/jetpack/androidx/releases/games)\n- [Memory Advice API reference documentation](/reference/games/memory-advice/group/memory-advice)\n- [Memory Advice sample on GitHub](https://github.com/android/games-samples/blob/main/agdk/agdktunnel/app/src/main/cpp/memory_consumer.cpp#L168)\n- [Memory Advice API source code](https://android.googlesource.com/platform/frameworks/opt/gamesdk/+/refs/heads/master/games-memory-advice/)\n\nIssues and Feedback\n\nThe Memory Advice API is in beta and welcomes feedback, if you have suggestions or\nfind issues while using the API, [create an issue in IssueTracker](https://issuetracker.google.com/issues/new?component=897320&template=1456805)."]]