以上就是给各位分享.NETMemoryissuesloading~40images,memorynotreclaimed,potentiallyduetoLOHfragmentation,同时本文还将
以上就是给各位分享.NET Memory issues loading ~40 images, memory not reclaimed, potentially due to LOH fragmentation,同时本文还将给你拓展2019-02-13 Python爬虫问题 NotImplementedError: Only the following pseudo-classes are implemented: nth...、Alter table `timo`.`sys_action_log` ENGINE=MEMORY 失败了?咋整 ENGINE=MEMORY 失败了、Android DialogFragment 遇到 java.lang.IllegalStateException: Fragment already added: 的解决方法、Attempted to read or write protected memory. This is often an indication that other memory is corrupt.等相关知识,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:- .NET Memory issues loading ~40 images, memory not reclaimed, potentially due to LOH fragmentation
- 2019-02-13 Python爬虫问题 NotImplementedError: Only the following pseudo-classes are implemented: nth...
- Alter table `timo`.`sys_action_log` ENGINE=MEMORY 失败了?咋整 ENGINE=MEMORY 失败了
- Android DialogFragment 遇到 java.lang.IllegalStateException: Fragment already added: 的解决方法
- Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
.NET Memory issues loading ~40 images, memory not reclaimed, potentially due to LOH fragmentation
Well, this is my first foray into memory profiling a .NET app (CPU tuning I
have done) and I am hitting a bit of a wall here.
I have a view in my app which loads 40 images (max) per page, each running
about ~3MB. The max number of pages is 10. Seeing as I don’t want to keep 400
images or 1.2GB in memory at once, I set each image to null when the page is
changed.
Now, at first I thought that I must just have stale references to these
images. I downloaded ANTS profiler (great tool BTW) and ran a few tests. The
object lifetime graph tells me that I don’t have any references to these
images other than the single reference in the parent class (which is by
design, also confirmed by meticulously combing through my code):
The parent class SlideViewModelBase
sticks around forever in a cache, but
the MacroImage
property is set to null when the page is changed. I don’t see
any indication that these objects should be kept around longer than expected.
I next took a look at the large object heap and memory usage in general. After
looking at three pages of images I have 691.9MB of unmanaged memory allocated
and 442.3MB on the LOH. System.Byte[]
, which comes from mySystem.Drawing.Bitmap
to BitmapImage
conversion is taking pretty much all
of the LOH space. Here is my conversion code:
public static BitmapSource ToBmpSrc( this Bitmap b ){ var bi = new BitmapImage(); var ms = new MemoryStream(); bi.CacheOption = BitmapCacheOption.OnLoad; b.Save( ms, ImageFormat.Bmp ); ms.Position = 0; bi.BeginInit(); ms.Seek( 0, SeekOrigin.Begin ); bi.StreamSource = ms; bi.EndInit(); return bi;}
I am having a hard time finding where all of that unmanaged memory is going. I
suspected the System.Drawing.Bitmap
objects at first, but ANTS doesn’t show
them sticking around, and I also ran a test where I made absolutely sure that
all of them were disposed and it didn’t make a difference. So I haven’t yet
figured out where all of that unmanaged memory is coming from.
My two current theories are:
- LOH fragmentation. If I navigate away from the paged view and click a couple of buttons about half of the ~1.5GB is reclaimed. Still too much, but interesting nonetheless.
- Some weird WPF binding thing. We do use databinding to display these images and I am no expert in regards to the ins and outs of how these WPF controls work.
If anyone has any theories or profiling tips I would be extremely grateful as
(of course) we are on a tight deadline and I am scrambling a bit to get this
final part done and working. I think I’ve been spoiled by tracking down memory
leaks in C++ … who woulda’ thought?
If you need more info or would like me to try something else please ask. Sorry
about the wall-o-text here, I tried to keep it as concise as possible.
答案1
小编典典This blog
post
appears to descibe what you are seeing, and the proposed solution was to
create an implementation of Stream that wraps another
stream.
The Dispose method of this wrapper class needs to release the wrapped stream,
so that it can be garbage collected. Once the BitmapImage is initialised with
this wrapper stream, the wrapper stream can be disposed, releasing the
underlying stream, and allowing the large byte array itself to be freed.
The BitmapImage keeps a reference to the source stream so it keeps the
MemoryStream object alive. Unfortunately, even though MemoryStream.Dispose
has been invoked, it doesn’t release the byte array that the memory stream
wraps. So, in this case, bitmap is referencing stream, which is referencing
buffer, which may be taking up a lot of space on the large object heap.
There isn’t a true memory leak; when there are no more references to bitmap,
all these objects will (eventually) be garbage collected. But since bitmap
has already made its own private copy of the image (for rendering), it seems
rather wasteful to have the now-unnecessary original copy of the bitmap
still in memory.
Also, what version of .NET are you using? Prior to .NET 3.5 SP1, there was a
known issue where a BitmapImage could cause a memory
leak. The workaround was to call
Freeze on the
BitmapImage.
2019-02-13 Python爬虫问题 NotImplementedError: Only the following pseudo-classes are implemented: nth...
soup=BeautifulSoup(html.text,''lxml'')
#data=soup.select(''body > div.main > div.ctr > div > div.newsmcont > p:nth-of-type(3) > img'')
#data=soup.select(''body > div.main > div.ctr > div > div.newsmcont > p > img'')[2]
data=soup.select(''body > div.main > div.ctr > div > div.newsmcont > p:nth-child(3) > img'')
print(data)
当使用copy selector时,复制的是nth-child,而soup 似乎不支持nth-child,所以会报以下错误:
NotImplementedError: Only the following pseudo-classes are implemented: nth-of-type.
将nth-child 改为 nth-of-type 就可以了。
或者去掉nth-child,在后面加上[i-1],即[2]。
关于nth-child 和 nth-type,他们都是取父元素下的第n个元素,他们的区别可以通过下面这个例子了解一下:
<div>
<ul>
<p>zero</p>
<li>one</li>
<li>two</li>
</ul>
</div>
上面这个例子,.demo li:nth-child(2)
选择的是<li>one</li>
节点,而.demo li:nth-of-type(2)
则选择的是<li>two</li>
节点。
Alter table `timo`.`sys_action_log` ENGINE=MEMORY 失败了?咋整 ENGINE=MEMORY 失败了
我想更改 表的 数据 引擎 , 为何不成功,是何道理?
Alter table `timo`.`sys_action_log`
ENGINE=MEMORY
ALTER command denied to user ''tet''@''192.168.1.103'' for table ''sys_action_log''
Android DialogFragment 遇到 java.lang.IllegalStateException: Fragment already added: 的解决方法
使用AppCompatDialogFragment 或者 DialogFragment 的过程中遇到java.lang.IllegalStateException: Fragment already added: 的解决方法:
private CountryChooseDialog mCountryChooseDialog;
private void showCountryChooseDialog() {
if (mCountryChooseDialog == null) {
mCountryChooseDialog = CountryChooseDialog.newInstance();
}
if (mCountryChooseDialog.isAdded()) { //解决方法就是添加这行代码,如果已经添加了,就移除掉然后再show,就不会出现Fragment already added的错误了。
getSupportFragmentManager().beginTransaction().remove(mCountryChooseDialog).commit();
}
mCountryChooseDialog.show(getSupportFragmentManager(), mCountryChooseDialog.getClass().getName());
}
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.Exception Details: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Source Error:
Line 37: protected void Application_Start(Object sender, EventArgs e) Line 38: { Line 39: AppStartLogger.ResetLog(); Line 40: AppStartLogger.WriteLine("Starting AspDotNetStorefront..."); Line 41:
Source File: e:\Just\JustWeb\App_Code\Global.asax.cs Line: 39
Symptoms
Accessing the site results in an "Attempted To Read Or Write Protected Memory" error.
Cause
There are 2 potential causes of this issue:
1 - A site running a version of the ASPDNSF software older than 7.0.2.5 is attempting to run in a medium-trust hosting environment.
2 - A site running a version of the ASPDNSF software older than 7.0.2.5 is running on a host that has just applied the .NET 3.5 SP1 upgrade to the servers.
NOTE: In both of these cases, the problem lies with the environment the software is running in, as configured by the host. These are not flaws in the software, and are beyond our control.
Procedure
The best solution (regardless of which of the 2 causes above is creating your issue) is to upgrade to version 7.0.2.5 SP1 or higher of the ASPDNSF software. Those later versions can run natively in medium-trust (thus avoiding issue #1) and work fine with the latest .NET service pack (which didn't even exist before then for us to test against).
If upgrading is not an option at the moment, there are other workarounds for each possible cause. Note that these are the ONLY workarounds. We can provide no other advice than these steps:
Medium Trust:
1 - First, have the host or server admin apply the Microsoft-created hotfix available at
http://connect.microsoft.com/VisualStudio/Downloads/DownloadDetails.aspx?DownloadID=6003
2 - Contact support and request a special medium-trust build of the software. We will need a valid order number to provide that.
3 - Move to a full-trust environment (this may mean switching hosts).
.NET 3.5 SP1 Patch:
1 - Have the host roll back the changes on the server, or move your site to a server that has not had the patch applied.
https://support.aspdotnetstorefront.com/index.php?_m=knowledgebase&_a=viewarticle&kbarticleid=208
If you are using aspdotnetstorefront and are getting the following error: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
then please contact aspdotnetstorefront in regards to the error as you will have to upgrade your aspdotnetstorefront storefront application to version 7.0.2.5 SP1 or version 7.1.0.0 if the .NET 3.5 service pack is installed.
If you are not using aspdotnetstorefront and are getting this error, you will need to verify that you code works with the lates dotnet service packs for all versions. This error is usually remoting related, but not always.
今天的关于.NET Memory issues loading ~40 images, memory not reclaimed, potentially due to LOH fragmentation的分享已经结束,谢谢您的关注,如果想了解更多关于2019-02-13 Python爬虫问题 NotImplementedError: Only the following pseudo-classes are implemented: nth...、Alter table `timo`.`sys_action_log` ENGINE=MEMORY 失败了?咋整 ENGINE=MEMORY 失败了、Android DialogFragment 遇到 java.lang.IllegalStateException: Fragment already added: 的解决方法、Attempted to read or write protected memory. This is often an indication that other memory is corrupt.的相关知识,请在本站进行查询。
本文标签: