在本文中,我们将带你了解Computer-memory在这篇文章中,同时我们还将给您一些技巧,以帮助您实现更有效的.NETMemoryissuesloading~40images,memorynotr
在本文中,我们将带你了解Computer-memory在这篇文章中,同时我们还将给您一些技巧,以帮助您实现更有效的.NET Memory issues loading ~40 images, memory not reclaimed, potentially due to LOH fragmentation、/sys/fs/cgroup/memory/memory.limit_in_bytes 在 Fedora 33 中不存在、A Self-Organized Computer Virus Demo in C、Alter table `timo`.`sys_action_log` ENGINE=MEMORY 失败了?咋整 ENGINE=MEMORY 失败了。
本文目录一览:- Computer-memory
- .NET Memory issues loading ~40 images, memory not reclaimed, potentially due to LOH fragmentation
- /sys/fs/cgroup/memory/memory.limit_in_bytes 在 Fedora 33 中不存在
- A Self-Organized Computer Virus Demo in C
- Alter table `timo`.`sys_action_log` ENGINE=MEMORY 失败了?咋整 ENGINE=MEMORY 失败了
Computer-memory
几种存储器之间的比较
类 型 | 保持数据 | 可 写 | 擦除大小 | 擦除次数 | 价 格 | 读写速率 |
静态RAM | √ | √ | 字节 | 无限 | 昂贵 | 快 |
动态RAM | √ | √ | 字节 | 无限 | 中等 | 中等 |
ROM | × | × | 便宜 | 快 | ||
PROM | × | 一次使用编程器 | 中等 | 快 | ||
EPROM | × | √ 使用编程器 | 整个芯片 | 有限 | 中等 | 快 |
EEPROM | × | √ | 字节 | 有限 | 昂贵 | 读快 写慢 |
Flash | × | √ | 区 | 有限 | 中等 | 读快 写慢 |
NVRAM | × | √ | 字节 | 无限 | 昂贵 | 快 |
.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.
/sys/fs/cgroup/memory/memory.limit_in_bytes 在 Fedora 33 中不存在
如何解决/sys/fs/cgroup/memory/memory.limit_in_bytes 在 Fedora 33 中不存在
我有一个可以做的旧脚本
$(cat /sys/fs/cgroup/memory/memory.limit_in_bytes)
在 fedora 33 中没有这个文件。
我该怎么做才能解决这个问题?
谢谢。
解决方法
该问题与新的 cgroup v2 相关。 要解决此问题,请将 cgroup 恢复为 v1:
sudo sed -i ''/^GRUB_CMDLINE_LINUX/ s/"$/ systemd.unified_cgroup_hierarchy=0"/'' /etc/default/grub
然后重启。
在此之后 /sys/fs/cgroup/memory/memory.limit_in_bytes 将出现。
,重启前需要重做命令重新生成grub。 对于 Fedora 33,命令是:
BIOS
grub2-mkconfig -o /boot/grub2/grub.cfg
UEFI
grub2-mkconfig -o /boot/efi/EFI/fedora/grub.cfg
A Self-Organized Computer Virus Demo in C
A Program that can modify herself and copy herself to somewhere else and execute it. Just like gene-transformable virus.
Here''s the sample code.
#include "stdio.h"
#include "windows.h"
#define MAX_LOOP 10000
int main(int argc, const char** argv)
{
/*** THE VIRUS LOGIC PART ***/
//GENE_MARK
int a = 0;
printf("GENE PRINT:%d\n", a);
/*** THE VIRUS LOGIC PART ***/
// FILE NAME
char file_name[30] = "test";
// MAKE A COPY OF HERSELF
FILE* source = fopen("test.c", "r");
FILE* descendant = fopen("descendant.c", "w+");
printf("SOURCE FILE OPEN RESULT IS : %d \n", (int)source);
printf("DESCENDANT FILE CREATED: %d \n", (int)descendant);
if(descendant==NULL)
{
printf("ERROR ON CREATING DESCENDANT.\n");
return -1;
}
char buff[100] = {0};
// REPLACE GENE MARK PROGRAM
char letter = 0;
// GENE LINE
int idx = 0;
int loop = 0;
int buff_idx = 0;
while(!feof(source))
{
// ALARM
if(loop>MAX_LOOP)
break;
loop ++;
fread(&letter, sizeof(char), 1, source);
buff[buff_idx] = letter;
buff_idx ++;
if(letter==''\n'')
{
if(idx==9)
{
// TRANSFORM GENE
memset(buff, 0, 100);
buff_idx = 0;
strcat(buff, "int a = 1;\n");
}
fwrite(buff, sizeof(char), strlen(buff), descendant);
// CLEAR BUFFER
memset(buff, 0, 100);
buff_idx = 0;
idx ++;
}
}
// DEAL WITH LEFT LETTERS IN BUFFER
if(strlen(buff)>0)
{
strcat(buff, "\n");
fwrite(buff, sizeof(char), strlen(buff)+1, descendant);
}
// CLOSE ALL FILES
fclose(source);
fclose(descendant);
// until the descendant file is written over
/*** COMPILE HERSELF ***/
char* source_file = "descendant.c";
char* dest_file = "descendant.exe";
char command[100] = {0};
strcat(command, "gcc -o ");
strcat(command, dest_file);
strcat(command, " ");
strcat(command, source_file);
// COMPILATION
system(command);
/***********************/
printf("COPYING MYSELF DONE.\n");
printf("WAITING FOR NEXT INSTRUCTION...\n");
char cmd = getchar();
if(cmd==''Y'')
{
printf("BEGIN EXECUTE THE COPYFILE EXECUTION...\n");
//GENE_MARK
system("descendant.exe");
printf("EXECUTION PROCESS IS ACTIVATED, TASK DONE. EXIT SYSTEM.");
}
else
printf("YOU CHOOSE TO EXIT SYSTEM. BYE!");
return 0;
}
If you have any suggestions or ideas, please feel free comment below, thanks!
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''
今天关于Computer-memory的介绍到此结束,谢谢您的阅读,有关.NET Memory issues loading ~40 images, memory not reclaimed, potentially due to LOH fragmentation、/sys/fs/cgroup/memory/memory.limit_in_bytes 在 Fedora 33 中不存在、A Self-Organized Computer Virus Demo in C、Alter table `timo`.`sys_action_log` ENGINE=MEMORY 失败了?咋整 ENGINE=MEMORY 失败了等更多相关知识的信息可以在本站进行查询。
本文标签: