2012-02-03 81 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发行版(目前测试版),以解决这些问题。