2012-02-03 38 views
1

我有Web站點和Monotouch應用程序託管的WCF服務,它可以顯示和更新服務中的PDF文檔。 PDF文件大小可以從1字節到20 Mb。 當我有少量文檔(少於100個,文檔總大小爲30Mb)時,更新過程會成功完成。但是,當我有很多文件(超過300個,文件大小通常爲100Mb)時,我的程序在iPad 1上終止,但在iPad 2上仍然有效。我想在的問題。當iOS使用很多內存時,iOS會殺死我的應用。但我不知道問題出在哪裏,也許Monotouch GC不會從fileData字節數組中清除內存?在iPad上Monotouch和WCF,內存使用情況

方法,更新文件:

protected bool BeginUpdateProcess() 
{ 
    try { 
    var binding = new BasicHttpBinding(); 
    binding.MaxBufferSize = 52428800; 
    binding.MaxBufferPoolSize = binding.MaxReceivedMessageSize = 52428800L; 
    binding.ReaderQuotas.MaxStringContentLength = binding.ReaderQuotas.MaxArrayLength = 52428800; 
    var endpoint = new EndpointAddress(string.Format("http://{0}/Services/UpdateDataService.svc", UpdateInfo.Instance.ServerIP)); 
    using (var dataService = new UpdateDataServiceClient(binding, endpoint)) { 
     // Get document list for update 
     int[] docIds; 
     try { 
      docIds = dataService.GetModifiedDocumentIds(mLastUpdated); 
     } catch (Exception ex) { 
      LogWriter.Instance.WriteToLog("UpdateFromServiceEror: Can't load modified document ids list", ex); 
      return false; 
     } 

     // Get each document content and save it to iPad 
     for (int i = 0; i < docIds.Length; i++) { 
      if (Canceled) { 
       return true; 
      } 
      try { 
       byte[] fileData = dataService.GetDocumentTransData(docIds[i]); 
       SaveDocument(fileData); 
      } catch (Exception ex) { 
       LogWriter.Instance.WriteToLog(string.Format("Can't load or save file, id={0}", docIds[i]), ex); 
       return false; 
      } 
     } 
     dataService.Close(); 
    } 
} catch (Exception ex) { 
    LogWriter.Instance.WriteToLog("Error when update from service", ex); 
} 
} 

的網站WCF設置:

<serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> 
<behaviors> 
    <serviceBehaviors> 
     <behavior name="Default"> 
      <serviceMetadata httpGetEnabled="true"/> 
      <serviceDebug includeExceptionDetailInFaults="true"/> 
     </behavior> 
    </serviceBehaviors> 
</behaviors> 

<bindings> 
    <basicHttpBinding> 
     <binding name="Transport" 
      closeTimeout="00:01:00" 
      openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" 
      allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" 
      maxBufferSize="52428800" maxBufferPoolSize="524288" maxReceivedMessageSize="52428800" 
      messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" 
      useDefaultWebProxy="true"> 
      <readerQuotas maxDepth="64" 
         maxStringContentLength="52428800" 
         maxArrayLength="52428800" 
         maxBytesPerRead="16384" 
         maxNameTableCharCount="16384" /> 
     </binding> 
    </basicHttpBinding> 
</bindings> 

<services> 
    <service name="iDict.Site.Services.UpdateDataService" behaviorConfiguration="Default"> 
     <host> 
      <baseAddresses> 
       <add baseAddress="http://localhost:57709/Services/UpdateDataService.svc"/> 
      </baseAddresses> 
     </host> 
     <endpoint address="" binding="basicHttpBinding" bindingConfiguration="Transport" contract="iDict.Site.Services.IUpdateDataService" /> 
    </service> 
</services> 

+0

我不確定你的意思是**常見大小**?它看起來像**總**尺寸,例如*當我的文件很少(低於100,文件的普通尺寸是30Mb)時,*會變成「當我有**少數**文件時,**少於100,**總數**大小的文件是30MB ... – poupou 2012-02-03 18:19:34

+0

是的,你是對的,我糾正了我的問題。 – alexmac 2012-02-03 19:02:03

回答

1

這裏有幾件事情,可以幫助你:

  • 52428800是ab用於設備的ig緩衝區;

  • 是否將PDF文檔轉換爲XML?如果是這樣的話,在某種程度上,你的PDF文檔將在string(效率不高,內存明智)和byte[] fileData。這可能會超過第一代iPad的可用RAM。避免這種情況的一種可能方式是讓Web服務將URL返回到文件。然後,每個URL可以很容易地從Web服務器編輯到本地文件,而不需要太多內存;

  • iPad2有更多的RAM上面可能對他們有效,但這最終會失敗的更大的文件。同時使用Stream會限制您使用設備的存儲空間;

  • 根據您使用的MonoTouch的版本,可能會打bug #386。如果您可以,我建議您嘗試最新的MonoTouch發行版(目前測試版),以解決這些問題。