Android 应用优化避免 OutOfMemoryError
我有一个 Android 13mb 应用程序,它显示 SD 卡中的离线/缓存地图。我正在使用 mapnik 地图源,并且有 33, 000 个地图图块。
m_mapView.setTileSource(TileSourceFactory.MAPNIK);
问题:
查看地图时,加载地图图块需要时间。此外,滚动时会冻结约2-3秒,然后强制关闭。我可以使用try catch吗?
I have an Android 13mb application, which displays offline/cached map from sd card. I am using mapnik mapsource, and has 33, 000 map tiles.
m_mapView.setTileSource(TileSourceFactory.MAPNIK);
Problem:
When viewing the map, it takes time to load the maptiles. Furthermore, when scrolling it will freeze for about 2-3 seconds, then it will force closed. Can I use try catch?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果这些图像很大或很多,那么您可能没有足够的内存来一次将它们全部保存在内存中。您必须找到一种方法来智能地加载和卸载切片以适应可用的堆空间(32MB)。
但是,我有另一个猜测:您是否对不再需要的 Bitmap 对象调用了 recycle() ?如果不这样做,即使有足够的内存,您也会很快收到此错误。
If these images are large or many, then you may simply not have enough memory to keep them all in memory at once. You will have to find a way to intelligently load and unload the tiles to fit into available heap space, which is 32MB.
However, I have another guess: are you calling
recycle()
on theBitmap
objects that you do not need anymore? if you don't you can quickly get this error, even when there is enough memory.我不知道图块到底是如何显示的,但无论如何,这里有一些要点:
I don't know how exactly the tiles are displayed but some points here anyway: