1

我包含的工作示例代码显示了 IE 9 中的泄漏。(几分钟内 1 Gb)。当您将 V3.8 更改为 V3.7 时,不会发生此内存泄漏!!!所以我的猜测是它是在 v3.8 中引入的!该代码似乎在 Chrome/Firefox 中工作,但我正在开发一个 C# Winform 应用程序,并使用嵌入式 .NET webcontrol,一个围绕 IE 的 COM 包装器。已经尝试过 gecko .NET 组件,但这对我来说别无选择。

我被困在这里并且绝望,所以如果有人愿意提供解决方案......

谢谢罗伯

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" lang="en">
    <head>
      <meta http-equiv="content-type" content="text/html; charset=utf-8" />
      <title>Memoryleak in IE</title>

      <style type="text/css">
            html
            {
            }
            body
            {
                margin: 0px;
                padding: 0px;
            }

        </style>
        <style type="text/css">
            .context
            {
                font-family: Arial, sans-serif;
                text-decoration: none;
                color: #4444ff;
                font-size: small;
            }
            a:hover div
            {
                background: #00eeee;
            }
        </style>

      <script src="https://maps.googleapis.com/maps/api/js?sensor=false&amp;v=3.8" type="text/javascript"></script>
      <script type="text/javascript">

         var coords = [
    -115.821139332819,51.2247937004413,
    -115.821139332819,51.2247937004413,
    -115.820783024602,51.2247102926052,
    -115.820783024602,51.2247102926052,
    -115.820327685708,51.2246117850904,
    -115.820327685708,51.2246117850904,
    -115.819759388578,51.2244962798047,
    -115.819759388578,51.2244962798047,
    -115.819290270032,51.2244074438906,
    -115.819290270032,51.2244074438906,
    -115.818926957722,51.2243299769159,
    -115.818926957722,51.2243299769159,
    -115.818338387318,51.2242059504634,
    -115.818338387318,51.2242059504634,
    -115.817977304212,51.2241249042188,
    -115.817977304212,51.2241249042188,
    -115.817599143301,51.224042310143,
    -115.817599143301,51.224042310143,
    -115.817134937747,51.2239589216431,
    -115.817134937747,51.2239589216431,
    -115.816536085049,51.2238583513406,
    -115.816536085049,51.2238583513406,
    -115.816082549208,51.2237586568853,
    -115.816082549208,51.2237586568853,
    -115.815700862212,51.2236505400057,
    -115.815700862212,51.2236505400057,
    -115.815357631111,51.223555251529,
    -115.815357631111,51.223555251529,
    -115.814809515585,51.2234021852219,
    -115.814809515585,51.2234021852219,
    -115.814355814815,51.2232968327074,
    -115.814355814815,51.2232968327074,
    -115.813999142875,51.2231965005283,
    -115.813999142875,51.2231965005283,
    -115.813647699181,51.2230910623849,
    -115.813647699181,51.2230910623849,
    -115.813026822773,51.2229353329219,
    -115.813026822773,51.2229353329219,
    -115.812582641159,51.2228335929039,
    -115.812582641159,51.2228335929039,
    -115.812013680777,51.2226994808324,
    -115.812013680777,51.2226994808324,
    -115.811661976828,51.2225955792611,
    -115.811661976828,51.2225955792611,
    -115.811254131518,51.2224819086399,
    -115.811254131518,51.2224819086399,
    -115.810894380211,51.2223965803553,
    -115.810894380211,51.2223965803553,
    -115.810314308135,51.2222515485398,
    -115.810314308135,51.2222515485398,
    -115.809965253975,51.2221524009482];


        var myPano = null;
        var mySVC  = null;
        var sv     = new google.maps.StreetViewService();
        var teller = 0;
        var tmr    = null;

        function startStreetviewMode(lat, lon)
        {
            try
            {
                var svPanoramaOptions = {
                    visible:          true,
                    disableDoubleClickZoom: true,
                    linksControl:     true,
                    addressControl:   true,
                    panControl:       true,
                    zoomControl:      false,
                    imageDateControl: false,
                    position:         new google.maps.LatLng(lat, lon),
                    pov: {
                         heading: 180,
                         pitch:   0,
                         zoom:    1
                         }
                    };

                myPano = new google.maps.StreetViewPanorama(document.getElementById("pano"), svPanoramaOptions);
                myPano.setVisible(true);

                svPanoramaOptions = null;
            }
            catch (err)
            {
                alert("startStreetviewMode, " + err.source + ':' + err.message);
            }
       }

       function SVPanoInitialized(SVLocation)
       {
       }

       function handleSVError(errorCode)
       {
       }


       function showStreet(lat, lng)
       {
           try
           {
               sv.getPanoramaByLocation(new google.maps.LatLng(lat, lng), 50, function (data, status)
               {
                   if (status == google.maps.StreetViewStatus.OK)
                   {
                       myPano.setPov({
                           heading: 180,
                           pitch:   10,
                           zoom:    1
                       });
                       myPano.setPano(data.location.pano);
                       myPano.setVisible(true);
                       data   = null;
                       status = null;
                   }
                   else
                   {
                       handleSVError(status);
                   }
               });
            }
            catch (err)
            {
                alert("showStreet, " + err.source + ':' + err.message);
            }
        }

        function showit()
        {
            // Keep looping through array
            teller = teller + 2;
            if (teller > 80) teller = 0;

            // Show streetview to demonstrate leak
            showStreet(coords[teller + 1], coords[teller]);
        }

        function init()
        {
            startStreetviewMode(coords[teller + 1], coords[teller]);
          window.setInterval(this.showit, 750);
     }
    </script>
    </head>
    <body onload="init()">
        <div id="pano" style="width: 1024px; height: 768px" />
    </body>
    </html>
4

1 回答 1

0

已知无作用域(和全局作用域)变量会导致内存泄漏。我建议您确保所有变量都正确地限定为函数局部变量。

于 2012-05-18T09:09:21.903 回答