앱 메모리 최적화
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
메모리는 모든 소프트웨어 개발 환경에서 중요한 리소스이지만, 물리적 메모리의 제약이 발생하는 경우가 많은 모바일 운영체제에서는 더욱 중요합니다. Android(Go 버전)가 흔히 설치되는 네이티브 메모리 용량이 낮은 기기의 경우 특히 더 그렇습니다. 앱에서 메모리를 최적화하여 이러한 환경에서 원활하게 실행되도록 도와주는 몇 가지 방법이 있습니다.
권장사항
캐시 메모리 해제
일반적인 환경에서처럼 백그라운드 프로세스가 실행되는 상태로 유지하는 데 필요한 메모리가 없을 수 있습니다. 이 경우 onTrimMemory()
를 사용하여 앱의 프로세스에서 불필요한 메모리를 줄일 수 있습니다. 앱의 현재 줄임 수준을 가장 효과적으로 알아보려면 ActivityManager.getMyMemoryState(RunningAppProcessInfo)
를 사용하여 불필요한 리소스를 최적화하거나 줄입니다. 예를 들어 표현식, 검색, 뷰 캐시 또는 열 수 있는 확장 프로그램에서 불필요한 메모리 사용량을 줄이면 메모리 부족으로 인해 앱이 비정상 종료되거나 ANR이 발생하는 횟수를 줄일 수 있습니다.
태스크 예약
동시 예약은 여러 개의 메모리 집약적인 작업이 동시에 실행되도록 하여 앱의 최대 메모리 사용량을 초과하는 리소스를 두고 경합이 발생하는 결과를 낳을 수 있습니다. 프로세스를 올바른 스레드 풀의 CPU 집약적이고 지연 시간이 짧은 태스크로 분리함으로써 리소스가 다양한 리소스 제약조건이 발생할 수 있는 기기에서 실행될 수 있도록 적절히 할당해 보세요.
메모리 누수
다양한 도구(예:
Android 스튜디오의 메모리 프로파일러,
Perfetto)가 특히 앱 내에서 메모리 누수를 찾고 줄이는 데 도움이 되도록 제공됩니다. 앱의 다른 구성요소가 시스템에 추가 압력을 주지 않고 실행될 수 있도록 이러한 도구를 사용하여 잠재적인 메모리 문제를 식별하고 수정하는 것이 좋습니다.
기타 팁
- 큰 이미지나 드로어블은 앱에서 더 많은 메모리를 소비합니다. 대형 또는 전체 색상 비트맵을 찾아서 최적화하여 메모리 사용량을 줄이세요.
- GIF는 메모리를 많이 사용하므로 Android(Go 버전)용으로 빌드할 때는 앱에서 GIF를 위해 다른 옵션을 사용해 보세요.
- WebP, pngcrush, pngquant 등의 도구를 사용하면 이미지 품질 저하 없이 PNG 파일의 크기를 줄일 수 있습니다. 이러한 도구는 체감 이미지 품질을 유지하면서 PNG 파일 크기를 줄여 줍니다.
- aapt 도구는 빌드 프로세스 중에 무손실 압축을 사용하여
res/drawable/
에 있는 이미지 리소스를 최적화할 수 있습니다. 예를 들어 aapt 도구는 색상 팔레트를 사용하여 최대 256개 색상이 필요한 트루 컬러 PNG를 8비트 PNG로 변환할 수 있습니다. 이렇게 하면 품질은 동일하지만 메모리 사용량은 줄어든 이미지가 생성됩니다.
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 Oracle 계열사의 상표 또는 등록 상표입니다.
최종 업데이트: 2025-07-27(UTC)
[null,null,["최종 업데이트: 2025-07-27(UTC)"],[],[],null,["# Optimize app memory\n\nMemory is a valuable resource in any software development environment, but it's\neven more valuable on a mobile operating system where physical memory is often\nconstrained. This is especially true for natively low-memory devices found\ncommonly with Android (Go edition). There are a few ways to help optimize memory\nin your app to help it run smoothly in these environments.\n\nBest practices\n--------------\n\n### Release cache memory\n\nThere may not be enough memory to keep background processes running as you\nwould in a typical environment. In this case, you can use\n[`onTrimMemory()`](/reference/android/content/ComponentCallbacks2#onTrimMemory(int))\nto trim unneeded memory from your app's process. To best\nidentify the current trim level for your app, use\n[`ActivityManager.getMyMemoryState(RunningAppProcessInfo)`](/reference/android/app/ActivityManager#getMyMemoryState(android.app.ActivityManager.RunningAppProcessInfo))\nand optimize or trim any unnecessary resources. For example, you can trim\nunnecessary memory usage from\nexpressions, search, view cache, or openable extensions to reduce the number of\ntimes your app experiences crashes or ANRs due to low memory.\n\n### Task scheduling\n\nConcurrent scheduling can lead to multiple memory intensive operations to run\nin parallel, leading to competition for resources exceeding the peak memory\nusage of an app. Try to appropriately allocate resources by separating processes\ninto CPU intensive, low latency tasks in the right\n[thread pool](/guide/background/threading) to run on devices that may face\nvarious resource constraints.\n\n### Memory leaks\n\nVarious tools, such as\n[Memory Profiler](/studio/profile/memory-profiler) in Android Studio and\n[Perfetto](https://perfetto.dev/docs/case-studies/memory) are\nspecifically available to help find and reduce memory leaks within your app.\nIt's highly encouraged that you use these tools to identify and fix potential\nmemory issues to allow other components of your app to run without additional\npressure on the system.\n\n### Other tips\n\n- Large images or drawables consume more memory in apps. Identify and optimize large or full-colored bitmaps to reduce memory usage.\n- Try to choose other options for GIFs in your app when building for Android (Go edition) as GIFs consume a lot of memory.\n- You can reduce PNG file sizes without losing image quality using tools like [WebP](/studio/write/convert-webp), pngcrush, and pngquant. All of these tools can reduce PNG file size while preserving the perceptive image quality.\n- The aapt tool can optimize the image resources placed in `res/drawable/` with lossless compression during the build process. For example, the aapt tool can convert a true-color PNG that does not require more than 256 colors to an 8-bit PNG with a color palette. Doing so results in an image of equal quality but a smaller memory footprint."]]