- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
使用 RemoveRange 后,项目似乎保留在内存中。据我所知,没有关于这些项目的其他引用资料。我是否应该使用一种解决方法来复制我想要的项目并完全删除旧列表?
打个例子说明一下:
private void Form1_Load(object sender, EventArgs e)
{
bmp = new Bitmap(5000, 5000, PixelFormat.Format32bppPArgb);
pictureBox1.Image = bmp;
pictureBox1.Width = bmp.Width;pictureBox1.Height = bmp.Height;
bmp2 = new Bitmap(some_image_file);//500x500 bitmap
}
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
bitmap_list.Add(new Bitmap(bmp));
Graphics.FromImage(bmp).DrawImage(bmp2, e.X - bmp2.Width / 2, e.Y - bmp2.Height / 2);
pictureBox1.Refresh();
}
private void button1_Click(object sender, EventArgs e)
{// where do the items go? memory is not freed until running a manual GC
bitmap_list.RemoveRange(1, bitmap_list.Count - 1);
}
private void button2_Click(object sender, EventArgs e)
{// if this is not clicked, memory will run out even after clearing the list
// down to one item
GC.Collect();
}
谢谢!
最佳答案
移除对象的最后一个引用不会破坏它并释放内存,而是会在稍后垃圾收集器运行时发生。
但是,由于您的元素是一次性的(例如,它们实现了 IDisposable
),您应该调用要移除的元素的 Dispose()
,例如在移除之前从列表中。这将使实例确定性地清理非托管资源,而不是等待 GC 和终结器运行,从而使行为更像您预期的那样。
关于c# List<T> RemoveRange 删除的项目会发生什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36926642/
我不了解data.removeRange()如何影响我的数据副本。 void main() { int lengthdata = 50; List data = List.filled(len
HTML: Lorem ipsum dolor sit amet, consectetur adipisicing elit. Qui aliquam quod aperiam veniam
数据库中有 1 列(varchar)的表:“user1”、“user2”、“user3”。 一个内存列表:users = {"user1","user2"} 是否有任何方法可以使用 RemoveRan
我正在尝试从表中删除多行。 在常规 SQL Server 中,这很简单: DELETE FROM Table WHERE Table.Column = 'SomeRandomValue'
我正在使用 Moq 来测试调用 RemoveRange 的代码在 DbSet 上.我 mock 了上下文对象和DbSet ,但是当我尝试验证是否调用了 RemoveRange 时,我得到“预期对模拟调
使用 RemoveRange 后,项目似乎保留在内存中。据我所知,没有关于这些项目的其他引用资料。我是否应该使用一种解决方法来复制我想要的项目并完全删除旧列表? 打个例子说明一下: private v
我可以在文档中看到: java.util.AbstractList#removeRange 它需要二次时间: This implementation gets a list iterator posi
ArrayList 的 removeRange 工作很奇怪。检查下面的示例代码,我给反向输入。还以为名单被反删了。 例如:3 到 1 表示删除了三个元素(第 3、第 2 和第 1)。 但是,输出完全让
我不明白如何处理编译器报告的问题。我试图创建一个范围,但它说索引未知: //let range = matches.first!.range.location
如题。我知道它可能在删除的项目之前和之后合并 2 个子列表,但是在删除 LAST 元素时该方法的行为如何?换句话说:它是否以某种方式复制了位于删除索引之前的所有元素?我只是对在一个巨大的列表(假设 5
To remove a substring at a specified range, use the removeRange(_:) method: 1 let range = advance(we
我正在使用 .RemoveRange 从数据库中删除多条记录,但为此我必须先获取所有记录,然后将它们传递给 .RemoveRange,但我想在不从数据库?知道如何实现吗? db.People.Remo
这个问题在这里已经有了答案: Why is Java's AbstractList's removeRange() method protected? (1 个回答) 关闭 6 年前。 我正在尝试使
嗨,我是 Entity Framework 的新手,想知道在尝试从上下文中删除时什么更好。 使用 .RemoveRange 传递通过集合还是自己循环并调用 .Remove 方法更好? 无论如何,他们最
这段代码抛出异常 System.InvalidOperationException: The entity type 'List' was not found. Ensure that the ent
本文整理了Java中org.springframework.data.redis.core.ZSetOperations.removeRange()方法的一些代码示例,展示了ZSetOperation
有谁知道,为什么 AbstractList 中的 removeRange 方法(以及在 ArrayList 中)是否受到 protected 的保护?它看起来像是一个定义明确且有用的操作,但仍然要使用
Kotlin 有没有像 Java 一样删除特定范围内元素的函数。 在 Java 中,我们有一个名为 removeRange 的方法,它可以被扩展并变得有用。 expect class ArrayLis
有谁知道为什么在下面的代码中离开 while 循环体后的长度为零?请不要向我提供分块算法我已经知道了几种这样的算法并且我知道如何解决这个问题。我的问题只是关于 RemoverRange 或 Take
在 Joshua Bloch 的 Effective Java 一书中,讨论了类如何提供“明智选择的 protected 方法”作为其内部工作的 Hook 。 然后作者引用了 AbstractList
我是一名优秀的程序员,十分优秀!