2016-07-04 33 views
0

我想上傳大量的圖像到服務器說每個大小300 kb的圖像近100。當我嘗試上傳圖像時,15-18張圖像中的一些圖像會同步到服務器,但是應用程序關閉(僅存在),而logcat中沒有任何應用程序崩潰消息或錯誤。混合應用程序關閉沒有給logcat上的任何錯誤,而上傳圖像

這是一個記憶問題。可能是我沒有釋放個人圖像使用的內存。

這裏是我的同步圖像

function SyncImage(ImageName, TryCount) 
{ 
    var basicpath = localStorage.getItem('ImagePath'); 

    var Filename = Imagename; 
    var src = basicpath + Filename + "?" + new Date().getTime(); 
    // var src = "image.jpg"; 

    var myCanvas = document.createElement('canvas'); 
    var context = myCanvas.getContext('2d'); 

    var img1 = document.createElement('img'); 


    img1.onload = function() 
    { 
     var imgwidth = img1.width; 
     var imgheight = img1.height; 

     myCanvas.width = imgwidth; 
     myCanvas.height = imgheight; 

     context.drawImage(img1,10,10,imgwidth,imgheight); 
     //console.log("Image Ready"); 
     // alert("Image Ready"); 

     var myurl = myCanvas.toDataURL('image/jpeg'); 

     urlimage = Filename + myurl; 


     // console.log("contacting server"); 
     // alert("contacting server"); 

     var nRequest = new XMLHttpRequest(); 
     nRequest.open("POST", dbstatements.domain_address+"api/upload_image.php", true); 
     nRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); 
     nRequest.onreadystatechange = function (oEvent) 
     { 
      if (nRequest.readyState == 4) 
      { 
       if (nRequest.status == 200) 
       { 
        // console.log(Filename); 
        // alert("uploaded"); 
        return; 
       } 
       else 
       { 
        SyncImage(ImageName, Number(TryCount+1)); 
       } 
      } 
     }; 
     nRequest.send(urlimage); 


      img1.src = " "; 
      img1 = null; 

    } 

    img1.src = src; 

} 

代碼這是我的logcat輸出

07-05 17:28:13.317 12213-12213/com.example.ac046137.csm D/cr_Ime:  [InputMethodManagerWrapper.java:59] isActive: true 
07-05 17:28:13.318 12213-12213/com.example.ac046137.csm D/cr_Ime: [InputMethodManagerWrapper.java:68] hideSoftInputFromWindow 
07-05 17:28:19.010 12213-12213/com.example.ac046137.csm D/cr_Ime: [InputMethodManagerWrapper.java:42] restartInput 
07-05 17:28:19.014 12213-12213/com.example.ac046137.csm D/cr_Ime: [InputMethodManagerWrapper.java:50] showSoftInput 
07-05 17:28:19.027 12213-12213/com.example.ac046137.csm D/cr_Ime: [InputMethodManagerWrapper.java:77] updateSelection: SEL [0, 0], COM [-1, -1] 
07-05 17:28:19.085 12213-12213/com.example.ac046137.csm D/cr_Ime: [InputMethodManagerWrapper.java:89] updateCursorAnchorInfo 
07-05 17:28:19.732 12213-12213/com.example.ac046137.csm D/cr_Ime: [InputMethodManagerWrapper.java:89] updateCursorAnchorInfo 
07-05 17:28:53.402 12213-12213/com.example.ac046137.csm D/cr_Ime: [InputMethodManagerWrapper.java:77] updateSelection: SEL [3, 3], COM [-1, -1] 
07-05 17:28:53.448 12213-12213/com.example.ac046137.csm D/cr_Ime: [InputMethodManagerWrapper.java:89] updateCursorAnchorInfo 
07-05 17:28:53.513 12213-12213/com.example.ac046137.csm D/cr_Ime: [InputMethodManagerWrapper.java:77] updateSelection: SEL [3, 3], COM [0, 3] 
07-05 17:28:53.514 12213-12213/com.example.ac046137.csm D/cr_Ime: [InputMethodManagerWrapper.java:77] updateSelection: SEL [3, 3], COM [0, 3] 
07-05 17:28:53.549 12213-12213/com.example.ac046137.csm D/cr_Ime: [InputMethodManagerWrapper.java:89] updateCursorAnchorInfo 
07-05 17:28:53.806 12213-12213/com.example.ac046137.csm D/cr_Ime: [InputMethodManagerWrapper.java:42] restartInput 
07-05 17:28:53.810 12213-12213/com.example.ac046137.csm D/cr_Ime: [InputMethodManagerWrapper.java:77] updateSelection: SEL [3, 3], COM [-1, -1] 
07-05 17:28:53.811 12213-12213/com.example.ac046137.csm D/cr_Ime: [InputMethodManagerWrapper.java:77] updateSelection: SEL [3, 3], COM [-1, -1] 
07-05 17:28:53.814 12213-12213/com.example.ac046137.csm D/cr_Ime: [InputMethodManagerWrapper.java:89] updateCursorAnchorInfo 
07-05 17:28:53.849 12213-12213/com.example.ac046137.csm D/cr_Ime: [InputMethodManagerWrapper.java:42] restartInput 
07-05 17:28:53.861 12213-12213/com.example.ac046137.csm D/cr_Ime: [InputMethodManagerWrapper.java:42] restartInput 
07-05 17:28:53.865 12213-12213/com.example.ac046137.csm D/cr_Ime: [InputMethodManagerWrapper.java:50] showSoftInput 
07-05 17:28:53.868 12213-12213/com.example.ac046137.csm D/cr_Ime: [InputMethodManagerWrapper.java:77] updateSelection: SEL [0, 0], COM [-1, -1] 
07-05 17:28:53.869 12213-12213/com.example.ac046137.csm W/IInputConnectionWrapper: getTextBeforeCursor on inactive InputConnection 
07-05 17:28:53.878 12213-12213/com.example.ac046137.csm W/IInputConnectionWrapper: getTextBeforeCursor on inactive InputConnection 
07-05 17:28:53.880 12213-12213/com.example.ac046137.csm W/IInputConnectionWrapper: getTextBeforeCursor on inactive InputConnection 
07-05 17:28:53.937 12213-12213/com.example.ac046137.csm D/cr_Ime: [InputMethodManagerWrapper.java:89] updateCursorAnchorInfo 
07-05 17:28:54.197 12213-12213/com.example.ac046137.csm D/cr_Ime: [InputMethodManagerWrapper.java:89] updateCursorAnchorInfo 
07-05 17:28:54.851 12213-12213/com.example.ac046137.csm D/cr_Ime: [InputMethodManagerWrapper.java:77] updateSelection: SEL [1, 1], COM [-1, -1] 
07-05 17:28:54.916 12213-12213/com.example.ac046137.csm D/cr_Ime: [InputMethodManagerWrapper.java:89] updateCursorAnchorInfo 
07-05 17:28:55.209 12213-12213/com.example.ac046137.csm D/cr_Ime: [InputMethodManagerWrapper.java:77] updateSelection: SEL [2, 2], COM [-1, -1] 
07-05 17:28:55.263 12213-12213/com.example.ac046137.csm D/cr_Ime: [InputMethodManagerWrapper.java:89] updateCursorAnchorInfo 
07-05 17:28:55.628 12213-12213/com.example.ac046137.csm D/cr_Ime: [InputMethodManagerWrapper.java:77] updateSelection: SEL [3, 3], COM [-1, -1] 
07-05 17:28:55.668 12213-12213/com.example.ac046137.csm D/cr_Ime: [InputMethodManagerWrapper.java:89] updateCursorAnchorInfo 
07-05 17:28:56.135 12213-12213/com.example.ac046137.csm D/cr_Ime: [InputMethodManagerWrapper.java:59] isActive: true 
07-05 17:28:56.136 12213-12213/com.example.ac046137.csm D/cr_Ime: [InputMethodManagerWrapper.java:68] hideSoftInputFromWindow 
07-05 17:28:56.139 12213-12213/com.example.ac046137.csm D/cr_Ime: [InputMethodManagerWrapper.java:42] restartInput 
07-05 17:28:56.189 12213-12213/com.example.ac046137.csm W/cr_BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 12213 
07-05 17:28:58.693 12213-12213/com.example.ac046137.csm W/cr_BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 12213 
07-05 17:28:58.698 12213-12213/com.example.ac046137.csm D/cr_Ime: [InputMethodManagerWrapper.java:59] isActive: true 
07-05 17:28:58.698 12213-12213/com.example.ac046137.csm D/cr_Ime: [InputMethodManagerWrapper.java:68] hideSoftInputFromWindow 
07-05 17:29:30.407 12213-12213/com.example.ac046137.csm D/cr_Ime: [InputMethodManagerWrapper.java:59] isActive: true 
07-05 17:29:30.407 12213-12213/com.example.ac046137.csm D/cr_Ime: [InputMethodManagerWrapper.java:68] hideSoftInputFromWindow 
07-05 17:29:30.456 12213-12213/com.example.ac046137.csm D/cr_Ime: [InputMethodManagerWrapper.java:59] isActive: true 
07-05 17:29:30.457 12213-12213/com.example.ac046137.csm D/cr_Ime: [InputMethodManagerWrapper.java:68] hideSoftInputFromWindow 
07-05 17:29:31.383 12213-12213/com.example.ac046137.csm D/cr_Ime: [InputMethodManagerWrapper.java:59] isActive: true 
07-05 17:29:31.384 12213-12213/com.example.ac046137.csm D/cr_Ime: [InputMethodManagerWrapper.java:68] hideSoftInputFromWindow 

任何意見是極大的讚賞。謝謝

回答

0

你使用phonegap/cordova引擎嗎?

我建議你使用文件傳輸插件。因爲使用本地代碼上傳更有效。

網絡視圖內存有限。

+0

不,我只使用webview。我們的要求是我無法使用phonegap/cordova。有沒有解決這個問題的方法? – user6000866

+0

我與混合應用程序合作,我總是有這個問題(內存)。嘗試爲發送文件創建自己的本機代碼。 –

+0

因此,一旦每個圖像請求發送到服務器,我無法清除web視圖內存.... – user6000866

相關問題