销毁地图实例的正确方法是什么? [英] What is the Proper Way to Destroy a Map Instance?
问题描述
我最近开发了一个 html5 移动应用程序.该应用程序是一个页面,其中导航哈希更改事件替换了整个 DOM.该应用程序的一个部分是使用 API v3 的 Google 地图.在从 DOM 中删除地图 div 之前,我想删除所有事件处理程序/侦听器并释放尽可能多的内存,因为用户可能不会再次返回该部分.
I recently developed an html5 mobile application. The application was a single page where navigation hash change events replaced the entire DOM. One section of the application was a Google Map using API v3. Before the map div is removed from the DOM, I want to remove any event handlers/listeners and free up as much memory as possible as the user may not return to that section again.
销毁地图实例的最佳方法是什么?
What is the best way to destroy a map instance?
推荐答案
官方答案 你没有.单页应用程序中的地图实例应该被重用,而不是销毁然后重新创建.
The official answer is you don't. Map instances in a single page application should be reused and not destroyed then recreated.
对于某些单页应用程序,这可能意味着重新构建解决方案,这样一旦创建了地图,它就可能被隐藏或与 DOM 断开连接,但它永远不会被破坏/重新创建.
For some single page applications, this may mean re-architecting the solution such that once a map is created it may be hidden or disconnected from the DOM, but it is never destroyed/recreated.
这篇关于销毁地图实例的正确方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!