- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我有一个包含 100 个项目的列表。我必须每 1 分钟刷新一次列表。每次我更新列表 - RAM 都会增加。
private BindableCollection<MyObject> _list = new BindableCollection<MyObject>()
正如我所说,我必须每 1 分钟更新一次我的列表,所以我有一个每 1 分钟触发一次的事件。
private void OnListChanged(List<MyObject> list) {
_list.Clear();
_list.Addrange(list);
}
事件发生后,RAM 增加大约 10-20mb。问题是 RAM 永远不会减少......看起来 GC 不收集垃圾。
我尝试只更新显示前 10 个项目并只更新前 10 个项目,RAM 仍在增加,但速度较慢。
对于 View ,我使用的是 ListView:
<ListView
BorderThickness="0"
ItemTemplate="{StaticResource ItemTemplate}"
ItemsSource="{Binding ItemView}"
Focusable="False" />
我这样试过:
<ListView
ScrollViewer.CanContentScroll="True"
VirtualizingPanel.CacheLength="15"
VirtualizingPanel.IsVirtualizing="True"
VirtualizingPanel.CacheLengthUnit="Item"
VirtualizingPanel.VirtualizationMode="Recycling"
BorderThickness="0"
ItemTemplate="{StaticResource ItemTemplate}"
ItemsSource="{Binding ItemView}"
Focusable="False" />
但是虚拟化也没有帮助...
如果我在运行代码之前评论 ListView ,我会看到什么。 RAM 不再增加,所以这肯定是 Bindings 的问题......
谁能帮我解释一下问题出在哪里?
附言如果相关,我正在使用 Caliburn.Micro。
编辑
附言我尝试手动运行 GC,但没有任何反应。
P.P.P.S.我尝试使用内存分析器进行监控,但每个人都告诉我这是非托管内存,我不知道下一步该怎么做...
编辑
我发现了什么:
Yes, using List.Clear() clears the references to all objects in the list and sets the Count property to 0. It does not release the reference to the underlying array that stores the object references. You can set the Capacity property to 0 after clearing it to release the reference to that array.
If you actually have OOM problems then doing this is not exactly a cure, it can create more address space fragmentation trouble. Check this answer for hints on how to avoid creating too much garbage in the Large Object Heap.
但 BindableCollection 不具备清除容量的能力或可能性。
编辑
我退订了我订阅的所有事件,并通过单击按钮更新了我的列表。还是一样的问题...
最佳答案
我有一个类似的项目(cockpit builder),我在其中绑定(bind)了很多不同的 View 检查关联的 View 模型和 View 是否从内存中释放的解决方案:
你可以像这样放置析构函数:我在输出 View 中显示消息,但你可以设置断点进行调试
~ListViewModel()
{
System.Diagnostics.Debug.WriteLine("Listviewmodel released");
}
ListView.xaml.cs 中的列表也是如此
~ListView()
{
System.Diagnostics.Debug.WriteLine("Listview released");
}
如果您正在使用 EventAggregator 事件,如果您订阅了一个事件,请不要忘记取消订阅。如果您不这样做,则不会发布 View 和 View 模型。
如果您怀疑 bindcollection 使用大量 ram,为什么不这样做?:
private void OnListChanged(List<MyObject> list) {
_list.Clear();
_list = new BindableCollection<MyObject>()
_list.Addrange(list);
}
关于WPF ListView RAM 大幅增加,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57575189/
我需要从 1024 增加 FD_SETSIZE 值至 4096 .我知道最好使用 poll()/epoll()但我想了解什么是优点/缺点。主要问题是:我要重新编译glibc吗? ?我读了几个线程,其中
已关闭。这个问题是 not reproducible or was caused by typos 。目前不接受答案。 这个问题是由拼写错误或无法再重现的问题引起的。虽然类似的问题可能是 on-top
我在 HTML 文件中有这样的内容: var value = 0; add(x){ x++; do
有没有办法在用户向上滚动时增加变量,并在用户使用 JavaScript 向下滚动时减少变量?变量没有最大值或最小值,如果能够调整灵敏度就好了。我不知道从哪里开始,感谢您的帮助! 编辑:没有滚动条,因为
我是 ios 新手,遇到以下问题。 我想根据表格 View 中元素的数量增加和减少表格 View 的高度大小。如果在输入时客户端在输出时给出 3 个或超过 3 个元素,我希望看到一个比默认行大 2 行
所以我一直在四处搜索,似乎大多数人认为以下列方式递增 indexPath 是正确的方法: NSIndexPath *newIndexPath = [NSIndexPath indexPathForRo
我有一个关于 connSupervisionTimeout 的问题。 我正在使用 CoreBluetooth 编写应用程序。我检查了连接参数和 connSupervisionTimeout = 720
我正在尝试根据页面的滚动位置更改元素的填充;当用户向下滚动页面时,填充会增加,而当他们向上滚动时,填充会减少。 我的主要问题是滚动不是很流畅,有时如果我滚动到页面顶部太快,每次元素的填充大小都不一样。
我正在尝试计算 18456 个基因的相关性度量,但编译器 (Dev C) 在将宏 GENE 或 INDEX 增加到 4000 到 5000 之间的值后退出或大。例如,它适用于: # define GE
我有一个带有 position: absolute 和 CSS3 过渡的圆形元素(a 元素)。在 hover 事件中,我想增加圆的高度和宽度,但我想在所有边上添加像素,而不仅仅是在左侧或右侧。 示例如
为了改善用户体验,我计划在我网站的所有页面(A-、A、A+)上增加/减少/重置字体大小 我面临的问题是页面上不同元素使用的字体大小不统一。有些是 14px,有些是 18px,有些是 12px,有些是
本文实例讲述了Yii框架数据库查询、增加、删除操作。分享给大家供大家参考,具体如下: Yii 数据库查询 模型代码: ?
sql替换语句,用该命令可以整批替换某字段的内容,也可以批量在原字段内容上加上或去掉字符。 命令总解:update 表的名称 set 此表要替换的字段名=REPLACE(此表要替换的字段名, '原
sql不常用函数总结以及事务,增加,删除触发器 distinct 删除重复行 declare @x 申明一个变量 convert(varchar(20),t
要增加我使用的最大可用内存: export SPARK_MEM=1 g 或者我可以使用 val conf = new SparkConf() .setMaster("loca
我正在尝试将文本(自定义文本按钮)放入 AppBar 的前导属性中。但是,当文本太长时,文本会变成多行 Scaffold( appBar: AppBar( centerTi
我正在使用最新版本的 NetBeans,我需要增加输出和菜单的字体大小(不是代码部分)。我试过: netbeans_default_options=".... --fontsize 16" 但是当我将
我必须将 180000 个点绘制到一个 EPS 文件中。 使用标准 gnuplot 输出尺寸点彼此太接近,这使得它们无法区分。有没有办法增加图像的宽度和高度? 最佳答案 是的。 set termina
我有一个带有输入字段的 twitter bootstrap 3 导航栏。我想增加输入字段的宽度。我已尝试设置 col 大小,但它不起作用。 html比较长,请引用bootply http://www.
我正在尝试增加 ggplot 标题中下划线的大小/宽度/厚度。我曾尝试使用大小、宽度和长度,但没有成功。 这是我所做的一个例子。 test <- tibble(x = 1:5, y = 1, z =
我是一名优秀的程序员,十分优秀!