2012-01-28 15 views
0

メモリリーク。特にマップをズームし、サテライトボタンをクリックすると。 コード -GoogleマップAPI v3にとのUIWebView iOSのメモリの問題

<!DOCTYPE html> 
<html> 
<head> 
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> 
<style type="text/css"> 
    html { height: 100% } 
    body { height: 100%; margin: 0; padding: 0 } 
    #map_canvas { height: 100%;} 
    #route_table { height: 0%;} 
</style> 
<script type="text/javascript" 
    src="http://maps.googleapis.com/maps/api/js?sensor=true"> 
</script> 
<script type="text/javascript"> 

    var directionsDisplay = new google.maps.DirectionsRenderer(); 
    var directionsService = new google.maps.DirectionsService(); 
    var arrayInput = []; 
    var trafficLayer; 
    var map; 
    var markers = []; 
    var bounds; 
    var zoomWidth; 
    var alertBOOL; 

    function initialize() { 
    var txt = new String(%@); 
    arrayInput = txt.split(','); 
    //var latlng = new google.maps.LatLng(parseFloat(arrayInput[0]),parseFloat(arrayInput[1])); 
    var latlng = new google.maps.LatLng(-34.397, 150.644); 
    var myOptions = { 
     zoom: 5, 
     center: latlng, 
     disableDefaultUI:true, 
     streetViewControl:false, 
     backgroundColor: '#FFFFF', 
     mapTypeId: google.maps.MapTypeId.ROADMAP 
    }; 

    this.map = new google.maps.Map(document.getElementById("map_canvas"),myOptions); 
    directionsDisplay.setMap(this.map); 
    directionsDisplay.suppressInfoWindows = true; 
    addTrafficButton(); 
    addSatelliteButton(); 
    calcRoute(arrayInput); 
    } 

    function calcRoute(inputArray) { 
    var i=0; 
    var wps = []; 
    var start; 
    var end; 
    var i = 0; 
    var j=0; 
    for(i=0;i<arrayInput.length-1;i=i+2)  
    {  

     if(i==0) 
     {  
     start = new google.maps.LatLng(parseFloat(arrayInput[i]),arrayInput[i+1]); 
     this.map.center = start; 
     } 
     else if(i==(arrayInput.length-2)) 
     { 
     end = new google.maps.LatLng(parseFloat(arrayInput[i]),arrayInput[i+1]); 
     } 
     else 
     {  
     wps[j] = { location: new google.maps.LatLng(parseFloat(arrayInput[i]),arrayInput[i+1]) }; 
     j++; 
     } 

    } 
    bounds = new google.maps.LatLngBounds(start,end); 
    this.map.fitBounds(bounds); 
    var request = 
    { 
     origin:start, 
     destination:end, 
     waypoints: wps, 
     travelMode: google.maps.DirectionsTravelMode.DRIVING 
    }; 
    directionsService.route(request, function(result, status) 
    {  
     if (status == google.maps.DirectionsStatus.OK) 
     { 
     directionsDisplay.setDirections(result); 
     } 
    }); 
} 
function addTrafficButton() 
{ 
    var tbutton = document.createElement("button"); 
    tbutton.innerHTML = "Traffic On"; 
    tbutton.style.position = "absolute"; 
    tbutton.style.bottom = "50px"; 
    tbutton.style.right = "15px"; 
    tbutton.style.zIndex = 10; 
    tbutton.style.width = "70px"; 
    tbutton.style.height = "30px"; 
    this.map.getDiv().appendChild(tbutton); 
    tbutton.className = "lolight"; 
    tbutton.onclick = function() { 
    if (tbutton.className == "hilight") { 
     tbutton.innerHTML = "Traffic On"; 
     this.trafficLayer.setMap(null); 
     this.trafficLayer = null; 
     tbutton.className = "lolight"; 
    } else { 
     tbutton.innerHTML = "Traffic Off"; 
     this.trafficLayer = new google.maps.TrafficLayer(); 
     this.trafficLayer.setMap(this.map); 
     tbutton.className = "hilight"; 
    } 
    } 
} 

function addSatelliteButton() 
{ 
    var sbutton = document.createElement("button"); 
    sbutton.innerHTML = "Satellite"; 
    sbutton.style.position = "absolute"; 
    sbutton.style.bottom = "90px"; 
    sbutton.style.right = "15px"; 
    sbutton.style.zIndex = 10; 
    sbutton.style.width = "70px"; 
    sbutton.style.height = "30px"; 
    this.map.getDiv().appendChild(sbutton); 
    sbutton.className = "lolight"; 
    sbutton.onclick = function() { 
    if (sbutton.className == "hilight") { 
     sbutton.innerHTML = "Satellite"; 
     map.setMapTypeId(google.maps.MapTypeId.ROADMAP);  
     sbutton.className = "lolight"; 
    } else { 
     sbutton.innerHTML = "Map"; 
     sbutton.className = "hilight"; 
     map.setMapTypeId(google.maps.MapTypeId.HYBRID); 
    } 
    } 
} 

</script> 
</head> 
<body onload="initialize()"> 
    <div id="map_canvas" style="width:100%; height:100%;"></div> 
</body> 
</html> 

答えて

0

私はあなたの問題は、IOS 5にARCを使って解くことができると思います...それは、iOS 5へのりんごで追加し、それはアプリにメモリ全体の管理を保持している最高の機能です。 ARCと一緒に行くと、たくさんのことができます。

+0

私のアプリケーションは、iOS 4.xとiOSの5のためにあるの両方... – iosfanboy9

+0

はまだあなたは...あなたのアプリに問題があるので、私はそれのための適切な解決策を提供することができますので、あなたは、この時点で直面するどんな問題が伝えることができます。ズームしながら、あなたは...キャッシュポリシーを追加する必要がありますので、あなたのメモリが更新されますよりも、あなたのイメージが大きすぎる場合、私はあなたを助けることができるように15+ MBに2メガバイトから – Anjan

+0

のUIWebViewメモリの増加は... – iosfanboy9