Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Trang này trình bày các phương pháp hay nhất để dọn dẹp các phiên bản sau khi không còn cần thiết.
Sử dụng Navigator#clearDestinations và Navigator#cleanup khi phiên điều hướng hoàn tất
Để ngăn chặn tình trạng rò rỉ bộ nhớ và đảm bảo dọn dẹp đúng cách, hãy sử dụng Navigator#clearDestinations và Navigator#cleanup sau khi phiên điều hướng hoàn tất và không cần đến phiên bản Navigator nữa. Bạn có thể thực hiện việc này khi người dùng đã rời khỏi bản đồ và khi onDestroy() của hoạt động được liên kết được gọi.
Dọn dẹp các phần tử GoogleMap khi không còn cần thiết nữa
Nếu ứng dụng của bạn sử dụng một thực thể GoogleMap cho các trải nghiệm không phải là bản đồ chỉ đường, hãy nhớ dọn dẹp thực thể này khi không còn cần đến. Ví dụ: dọn dẹp các phần tử Đa giác, Đường nhiều đoạn và Điểm đánh dấu được liên kết với GoogleMap bằng cách gọi các phương thức Polygon#remove, Polyline#remove và Marker#remove tương ứng. Sau đó, để giải phóng phiên bản GoogleMap sau khi không cần đến nữa, hãy gọi GoogleMap#clear và chỉ định phiên bản đó cho null.
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-09-04 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)."]]