小编nik*_*iks的帖子

加载Mapview时,启动时应用程序崩溃(java.lang.OutOfMemoryError:确保本地容量)

安装后启动应用程序只会在Samsung手机上导致崩溃。在其他手机上不会发生。错误是

java.lang.OutOfMemoryError:确保本地容量:

仅在安装后首次启动应用程序时才发生崩溃。重新启动该应用程序时,它会运行,但会导致内存不断增加并且永远不会清除。

这是代码:

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
    val view= inflater.inflate(R.layout.fragment_place_search_results, container, false)
    mapView = childFragmentManager.findFragmentById(R.id.placesearchresults_map) as SupportMapFragment
    mapView.onCreate(savedInstanceState)
    mapView.getMapAsync(this)
    retainInstance = true
    return view
}

override fun onResume() {
    super.onResume()
    mapView.onResume()
}

override fun onPause() {
    super.onPause()
    mapView.onPause()
}

override fun onStart() {
    super.onStart()
    mapView.onStart()
}

override fun onDestroy() {
    super.onDestroy()
    map?.clear()
    mapView.onDestroy()
    mapMarkerFactor.recycle()
}

override fun onSaveInstanceState(outState: Bundle) {
    super.onSaveInstanceState(outState)
    mapView.onSaveInstanceState(outState)
}

override fun onLowMemory() {
    super.onLowMemory()
    mapView.onLowMemory()
}
Run Code Online (Sandbox Code Playgroud)

XML:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" …
Run Code Online (Sandbox Code Playgroud)

android google-maps memory-leaks android-mapview mapfragment

5
推荐指数
0
解决办法
315
查看次数