[英]Create and write an XML file throws the exception -> system out of memory exception?
[英]“Out of Memory” Exception when Decrypting an XML file
我正在使用System.Security.Cryptography庫來加密和解密xml文件。 盡管最近我在嘗試解密75MB文件時遇到了OOM(內存不足)異常。 這是我正在使用的代碼:
using System.Security.Cryptography.Xml;
...
public static XmlDocument DecryptIntoXmlDoc(string filename)
{
//Decrypt the XML
XmlDocument xmldoc = new XmlDocument();
EncryptedXml exml = new EncryptedXml(xmldoc);
TripleDESCryptoServiceProvider ekey = new TripleDESCryptoServiceProvider();
ASCIIEncoding encoding = new ASCIIEncoding();
ekey.Key = encoding.GetBytes(GetMasterKey());
exml.AddKeyNameMapping("ekey", ekey);
xmldoc.Load(filename);
// -- THROWS THE OOM ERROR --
exml.DecryptDocument();
//Clear exml
exml = null;
return xmldoc;
}
一旦調用.DecryptDocument(),我得到以下錯誤:
Exception of type 'System.OutOfMemoryException' was thrown.
我沒有找到其他人遇到這個問題,但是我已經讀到,如果xml標簽沒有正確命名/嵌套,那么在加載到內存中時文件可能會很大。 將XML標簽重命名為較短的名稱會減小大小嗎? 有沒有辦法嵌套xml標記以減小文件大小?
我還能做些什么嗎?
exml
的對象圖。 什么實際上占據了大部分內存? 不可變的字符串可能是殺手here,因為某些xml解析器可能最終將整個文檔保存在內存中多次。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.