The Memory Advice API beta is now deprecated, and no longer recommended for use.
Unity 게임용 Memory Advice API 시작하기
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
이 가이드에서는 Unity용 Memory Advice 플러그인을 사용하여 Memory Advice API를 Unity 게임에 통합하는 방법을 설명합니다.
요구사양
플러그인은 다음에서 지원됩니다.
Android NDK r19를 사용하는 Unity 2019
Android NDK r19를 사용하는 Unity 2020
Android NDK r21을 사용하는 Unity 2021
Android NDK r23을 사용하는 Unity 2022
다른 버전의 Unity와 Android NDK를 사용하는 경우 예기치 않은 문제가 발생할 수 있습니다. Unity 설치에 사용되는 NDK 버전을 찾으려면 Unity용 Android 환경 설정 가이드를 참고하세요.
플러그인 다운로드
플러그인을 다운로드합니다.
플러그인 가져오기
플러그인은 프로젝트에 가져올 수 있는 Unity 패키지입니다. 플러그인을 가져오려면 Assets(애셋) > Import Package(패키지 가져오기) > Custom Package(맞춤 패키지)를 클릭하고 다운로드한 .unitypackage
파일을 선택합니다. Unity 프로젝트를 연 후 .unitypackage
파일을 더블클릭해도 됩니다.
라이브러리 사용
이 섹션에서는 라이브러리 사용 방법을 설명합니다.
라이브러리 초기화
앱이 시작되면 라이브러리를 한 번 초기화해야 합니다.
프로젝트에 다음 코드를 추가하면 됩니다.
void Start()
{
MemoryAdviceErrorCode errorCode = MemoryAdvice.Init();
if(errorCode == MemoryAdviceErrorCode.Ok)
{
Debug.Log("Memory advice init successfully");
}
}
메모리 상태 폴링
지정한 간격으로 라이브러리를 폴링하여 앱의 메모리 상태를 가져올 수 있습니다. 라이브러리를 폴링해야 할 때마다 MemoryAdvice_getMemoryState 함수를 사용하세요.
MemoryState memoryState = MemoryAdvice.GetMemoryState();
switch (memoryState)
{
case MemoryState.Ok:
//The application can safely allocate memory.
break;
case MemoryState.ApproachingLimit:
// The application should minimize memory allocation.
break;
case MemoryState.Critical:
// The application should free memory as soon as possible
// until the memory state changes.
break;
}
감시자 설정
감시자를 설정하고 Memory Advice API를 등록할 수도 있습니다. 상태가 한계에 가까워지거나 중요한 메모리 상태가 되면 감시자 함수가 호출됩니다(일반적인 상태에서는 호출되지 않음). 예를 들어, 다음 코드는 감시자를 만들고 2초마다 Memory Advice API 알림을 요청합니다.
MemoryAdviceErrorCode errorCode = MemoryAdvice.RegisterWatcher(2000,
new MemoryWatcherDelegateListener((MemoryState state) =>
{
switch (memoryState)
{
case MemoryState.ApproachingLimit:
// The application should minimize memory allocation.
break;
case MemoryState.Critical:
// The application should free memory as soon as possible
// until the memory state changes.
break;
}
})
);
if(errorCode == MemoryAdviceErrorCode.Ok)
{
Debug.Log("Memory Advice watcher registered successfully");
}
다음 단계
메모리 할당 및 해제를 위한 간단한 UI를 제공하고 Memory Advice API를 사용하여 메모리 상태를 모니터링하는 Unity 샘플 프로젝트를 다운로드할 수 있습니다.
추가 리소스 및 문제 보고는 개요를 참고하세요.
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 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\nThis guide describes how to use the Memory Advice plugin for Unity to\nintegrate the\n[Memory Advice API](/games/sdk/memory-advice/overview) into\nyour Unity game.\n\nRequirements\n\nThe plugin is supported on:\n\n- Unity 2019 with Android NDK r19\n\n- Unity 2020 with Android NDK r19\n\n- Unity 2021 with Android NDK r21\n\n- Unity 2022 with Android NDK r23\n\nYou may face unexpected issues if you are using other versions of Unity and\nthe Android NDK. To find the NDK version used by your Unity installation, see\nthe\n[Android environment setup guide](https://docs.unity3d.com/Manual/android-sdksetup.html)\nfor Unity.\n\nDownload the plugin\n\nDownload [the plugin](https://dl.google.com/developers/android/games/memory_advice/memory-advice-1.0.0-beta01.unitypackage).\n\nImport the plugin\n\nThe plugin is a Unity Package that you can import into your project. To import\nthe plugin, click **Assets \\\u003e Import Package \\\u003e Custom Package** and select the\n`.unitypackage` file you downloaded. You can also double-click the\n`.unitypackage` file after opening your Unity project.\n\nUse the library\n\nThis section describes how to use the library.\n\nInitialize the library\n\nYou need to initialize the library once when the app starts.\nTo do so, add this code to your project: \n\n void Start()\n {\n MemoryAdviceErrorCode errorCode = MemoryAdvice.Init();\n if(errorCode == MemoryAdviceErrorCode.Ok)\n {\n Debug.Log(\"Memory advice init successfully\");\n }\n }\n\nPoll for memory state\n\nYou can retrieve the memory state of your app by polling the library at the\ninterval of your choosing. Use the [MemoryAdvice_getMemoryState](/reference/games/memory-advice/group/memory-advice#memoryadvice_getmemorystate)\nfunction whenever you need to poll the library: \n\n MemoryState memoryState = MemoryAdvice.GetMemoryState();\n switch (memoryState)\n {\n case MemoryState.Ok:\n //The application can safely allocate memory.\n break;\n case MemoryState.ApproachingLimit:\n // The application should minimize memory allocation.\n break;\n case MemoryState.Critical:\n // The application should free memory as soon as possible\n // until the memory state changes.\n break;\n }\n\nSet up a watcher\n\nYou can also set up [a watcher](/reference/games/memory-advice/group/memory-advice#memoryadvice_registerwatcher)\nand register the Memory Advice API, and your watcher function\nwill get called when the state is either approaching the limit or the critical\n[memory state](/reference/games/memory-advice/group/memory-advice#memoryadvice_memorystate)\n(but not for the ok state). For example, the following code creates a watcher\nand requests a Memory Advice API notification every 2 seconds: \n\n MemoryAdviceErrorCode errorCode = MemoryAdvice.RegisterWatcher(2000,\n new MemoryWatcherDelegateListener((MemoryState state) =\u003e\n {\n switch (memoryState)\n {\n case MemoryState.ApproachingLimit:\n // The application should minimize memory allocation.\n break;\n case MemoryState.Critical:\n // The application should free memory as soon as possible\n // until the memory state changes.\n break;\n }\n })\n );\n\n if(errorCode == MemoryAdviceErrorCode.Ok)\n {\n Debug.Log(\"Memory Advice watcher registered successfully\");\n }\n\nWhat's next\n\nYou can download our [Unity sample project](https://dl.google.com/developers/android/games/memory_advice/sample.zip)\nthat provides a simple UI for allocating and freeing memory, and uses\nMemory Advice API to monitor the memory state.\n\nSee the [overview](/games/sdk/memory-advice/overview) for\n[additional resources](/games/sdk/memory-advice/overview#additional_resources)\nand [reporting issues](/games/sdk/memory-advice/overview#issues_and_feedback)."]]