memory-leaks - 匿名函数内存泄漏

标签 memory-leaks anonymous-function rust

得到的错误:

$ rustc leakyFunction.rs --test
$ ./leakyFunction 

running 1 test
test testForLeakage ... Unreclaimed object found at 0xb6d02d98: ((), (10))
leaked memory in rust main loop (1 objects)
leakyFunction: /home/havvy/rust/src/rt/memory_region.cpp:172:
    memory_region::~memory_region(): Assertion `false' failed.
Aborted (core dumped)

Rust 代码(减少测试用例):

use std;

type boxedFn = { theFn: fn () -> uint };

fn createClosure (closedUint: uint) -> boxedFn {
    { theFn: fn@ () -> uint { closedUint } }
}

#[test]
fn testForLeakage () {
    let aFn: boxedFn = createClosure(10);

    let myInt: uint = aFn.theFn();

    assert myInt == 10;
}

为什么会泄漏内存?

最佳答案

任何时候你看到内存泄漏,这都是 Rust 中的一个错误(除非你正在处理 native 代码......在这种情况下,我们的泄漏检测器可能不会发现它)。在本例中,问题是#1896。

关于memory-leaks - 匿名函数内存泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11441584/

相关文章:

javascript - 仅在 Chrome 中使用 addPoints() 的 HighCharts/HighStock 内存泄漏

java - 固定大小的 LinkedHashMap 内存泄漏?

c - 神秘变化的结构成员(涉及指针):

c# - 匿名类型的属性列表

rust - 如何创建具有计时时区的通用 Rust 结构?

java - 升级到 Android 4.2.2 后出现奇怪错误 - Activity 已泄漏 IntentReceiver

PHP use() 作用域函数?

php - 在 Laravel (PHP) 中访问匿名函数中的范围外变量

Rust 通过空格分割线 : No method collect found for type &str

installation - Rust 安装在适用于 Linux 的 Windows 子系统上失败 : could not rename component file