我正在阅读 android 文档 http://developer.android.com/reference/com/google/android/gms/maps/MapFragment.html 我遇到了这句话:
Any objects obtained from the GoogleMap is associated with the view. It's important to not hold on to objects (e.g. Marker) beyond the view's life. Otherwise it will cause a memory leak as the view cannot be released.
我不完全理解,我不确定它是否适用于我,但我只是想检查一下:这仅适用于 fragment 被销毁而主视图仍然存在的情况,对吗?我的 map fragment 是该布局的 xml 中的唯一元素,因此我假设当用户离开时,标记对象(以及其他所有对象)都会被销毁。我是对的,还是恰恰相反?
最佳答案
如果你看一个 fragment lifecycle你可以看到 View 可能会被破坏,而 fragment 仍然存在。它还可以在 fragment 被销毁之前重新创建 View 。这只是意味着您应该清理并创建 onCreateView 中的所有标记。和 onDestroyView回调代替。如果您将这些回调用于标记操作,您应该没问题。
关于java - android map 、标记和内存泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16899612/