BingMap frequent Add Pushpin and Delete Pushpin may cause memory leakage, bingmappushpin
During a recent performance test, I found the memory leakage (memory leak) Problem in BingMap. I found some foreign posts and found similar problems, but there is no good solution.
Https://social.msdn.microsoft.com/Forums/en-US/3226f255-2ae1-4718-b848-5f24e76b64b0/your-pushpins-are-broken-addremove-leads-to-memory-leak? Forum = bingmapsajax
After some attempts, I found a compromise solution and shared it.
Paste the Testing Code first:
<!DOCTYPE html><%--<meta http-equiv='x-ua-compatible' content='IE=7;IE=9' />--%>
Analyze the specific cause, that is, when pushpin is added to the map, an HTML element is actually added, but the _ layre is called only when the map is removed. remove (pushpin) or _ layer. removeAt (index), the two methods have the same effect, but the Pushpin object is removed from the EntityCollection set of BingMap, but the html object of Pushpin still exists in the memory, therefore, frequent addition and removal may result in increasing memory.
Test results:
1. Place the HTML element of cfsNew on the page, and add it to the map every time by taking the DOM element. The memory growth rate is about 10 MB per second.
2. Write the cfsNew HTML into a var string and assign it to Pushpin contentHTML. The memory growth rate is about 1 MB per second.
3. If you do not need Pushpin in HTML format, use the default Pushpin icon (water drop). The memory increases by 0.1 MB per second.
4. After the $ ('# cfsNew'). remove (); method is added, the memory continues to increase.
At present, I only solve this problem by manually removing HTML objects by deleting them. However, because the HTML of each icon is different, we also need to bind special attributes for such a tag, it makes great inconvenience to program development, but Microsoft still hopes to discover and solve this problem.