我试图通过HTTPWebRequest将大文件(大约30MB)的字节上传到某个服务器.问题是由于字节大小超过85000,因此它存储在LargeObjectHeap(LOH)中.问题是我的代码在LOH中至少创建了同一个对象的5个实例,即使在关闭响应流之后也没有从内存中删除.以下是导致此问题的代码段.在此代码块之前,LOH中只有一个文件实例.
using (IO.Stream requestStream = webReqest.GetRequestStream())
{
List<byte> uploadData = new List<byte>();
uploadData.AddRange(Encoding.UTF8.GetBytes(stringContainingHeaderInfo));
uploadData.AddRange(bytesOfTheLargeFile);
byte[] fileFullData = uploadData.ToArray();
requestStream.Write(fileFullData, 0, fileFullData.Length);
requestStream.Close();
uploadData.Clear();
uploadData = null;
fileFullData = null;
fileEntityBytes = null;
using (WebResponse webResponse = webRequest.GetResponse())
{
//Do Something with the response
}
}
Run Code Online (Sandbox Code Playgroud)
有没有办法进一步优化此代码块,以便在堆中创建更少数量的副本.
我注意到这种奇怪的工具提示行为.
如果我点击具有bootstrap工具提示的链接然后切换标签或最小化窗口然后回到主窗口,即使鼠标没有悬停它也会显示工具提示.
这是一个错误吗?还是正常的行为?
http://jsfiddle.net/4nhzyvbL/1/
HTML代码
<a data-original-title="Download" target="_blank" href="http://www.google.com/"
data-toggle="tooltip" title=""> click me and then come back to check me </a>
Run Code Online (Sandbox Code Playgroud)
CSS代码
@import url("http://maxcdn.bootstrapcdn.com/bootswatch/3.2.0/cerulean/bootstrap.min.css");
@import url("http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css");
@import url("http://netdna.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css");
Run Code Online (Sandbox Code Playgroud)
JS代码
$(function (){$('[data-toggle="tooltip"]').tooltip({});});
Run Code Online (Sandbox Code Playgroud)
当用户回到主窗口时,如何使工具提示不显示?即自动隐藏.
我正在开展一个报告时间报告的项目.现在我正在开发一个可以报告假期的功能.从迄今为止.但是,当您只需单击按钮发送而无需在我的两个字段中输入任何内容时,它将因为null异常而崩溃.
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Index(DateTime fromDate, DateTime toDate, string comment)
{
using (IDatabaseLayer db = new DatabaseLayer())
{
if (fromDate != null || toDate != null)
{
db.InsertVacation(Constants.CurrentUser(User.Identity.Name), fromDate, toDate, comment);
ViewData.Model = db.GetUserVacations(Constants.CurrentUser(User.Identity.Name));
}
}
SendVacationMail(fromDate, toDate, comment);
ViewData["posted"] = true;
return View();
}
Run Code Online (Sandbox Code Playgroud)
在调试它时,它不会触及此代码块,除非我的字段中包含值.