Google Maps JS v3 - detached DOM tree - memory leak?

后端 未结 1 481
面向向阳花
面向向阳花 2020-12-23 11:53

I have the following issue. I am removing all references to a google maps instance including markers via the setMap(null) option via the following code:

<
相关标签:
1条回答
  • 2020-12-23 12:36

    This is a known issue in Google Maps API v3 - even pure creation and destruction of google.maps object (no marker creation) results in memory leak. See Issue 3803: Bug: Destroying Google Map Instance Never Frees Memory.

    They reproduce the issue by creating a simple loop that creates and destroys the google.maps object. See

    http://jsfiddle.net/KWf4r/

    After pressing start, you will observe your browser to grow in memory until you press stop.

    The issue is not fixed and there doesn't seem to be an official workaround available. There is certainly a way, but it's not a clean workaround that apparently might stop working in next release of google maps api - citing the discussion:

    I've actually managed to find a semi-workable fix by manually destroying a lot of the elements that google maps creates (and removing listeners). However, I am using a lot of undocumented things to do this (I had to check in the chrome inspector to see what to try to remove), so this doesn't seem the right way to go.

    0 讨论(0)
提交回复
热议问题