인스턴스 정리 권장사항
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
이 페이지에서는 더 이상 필요하지 않은 인스턴스를 정리하는 권장사항을 설명합니다.
탐색 세션이 완료되면 Navigator#clearDestinations
및 Navigator#cleanup
사용
메모리 누수를 방지하고 적절한 정리를 보장하려면 탐색 세션이 완료되고 Navigator 인스턴스가 더 이상 필요하지 않은 후 Navigator#clearDestinations
및 Navigator#cleanup
를 사용하세요. 이는 사용자가 지도에서 벗어났을 때와 연결된 활동의 onDestroy()
가 호출될 때 실행할 수 있습니다.
더 이상 필요하지 않은 GoogleMap
요소 정리
앱이 탐색 이외의 지도 환경에 GoogleMap
인스턴스를 사용하는 경우 더 이상 필요하지 않은 인스턴스를 정리해야 합니다. 예를 들어 Polygon#remove
, Polyline#remove
, Marker#remove
메서드를 각각 호출하여 GoogleMap
와 연결된 다각형, 다중선, 마커 요소를 정리합니다. 그런 다음 더 이상 필요하지 않은 GoogleMap
인스턴스를 해제하려면 GoogleMap#clear
를 호출하여 인스턴스를 null
에 할당합니다.
앱에서 GoogleMap
인스턴스를 사용하는 방법에 관한 자세한 내용은 GoogleMap
상호작용 권장사항을 참고하세요.
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-08-31(UTC)
[null,null,["최종 업데이트: 2025-08-31(UTC)"],[[["\u003cp\u003eUse \u003ccode\u003eNavigator#clearDestinations\u003c/code\u003e and \u003ccode\u003eNavigator#cleanup\u003c/code\u003e when navigation sessions are completed to prevent memory leaks.\u003c/p\u003e\n"],["\u003cp\u003eClean up \u003ccode\u003eGoogleMap\u003c/code\u003e elements like Polygons, Polylines, and Markers by calling their respective \u003ccode\u003eremove\u003c/code\u003e methods when they are no longer needed.\u003c/p\u003e\n"],["\u003cp\u003eAfter a \u003ccode\u003eGoogleMap\u003c/code\u003e instance is no longer in use, call \u003ccode\u003eGoogleMap#clear\u003c/code\u003e and assign the instance to \u003ccode\u003enull\u003c/code\u003e to free up resources.\u003c/p\u003e\n"]]],[],null,["# Instance cleanup best practices\n\nThis page explains best practices for cleaning up instances after they are no\nlonger needed.\n\nUse `Navigator#clearDestinations` and `Navigator#cleanup` when navigation sessions are completed\n------------------------------------------------------------------------------------------------\n\nTo prevent memory leaks and ensure proper cleanup, use\n`Navigator#clearDestinations` and `Navigator#cleanup` after the navigation\nsession is completed and the Navigator instance is no longer needed. This can be\ndone when the user has navigated away from the map and when `onDestroy()` of the\nassociated activity is invoked.\n\nClean up `GoogleMap` elements when they are no longer needed\n------------------------------------------------------------\n\nIf your app uses a `GoogleMap` instance for non-navigation maps experiences, be\nsure to clean up this instance when it is no longer needed. For example, clean\nup the Polygon, Polyline, and Marker elements associated with `GoogleMap` by\ncalling the `Polygon#remove`, `Polyline#remove`, and `Marker#remove` methods,\nrespectively. Then, to free up the `GoogleMap` instance after it is not longer\nneeded, call `GoogleMap#clear` assign the instance to `null`.\n\nFor more information about using a `GoogleMap` instance in your app, see\n[`GoogleMap` interaction best\npractices](/maps/documentation/navigation/android-sdk/googlemap-interactions-best-practices)."]]