L'erreur obtenue:Anonyme Fonction fuites de mémoire
$ 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)
Le code de la rouille (réduite testcase):
use std;
type boxedFn = { theFn: fn() -> uint };
fn createClosure (closedUint: uint) -> boxedFn {
{ theFn: [email protected]() -> uint { closedUint } }
}
#[test]
fn testForLeakage() {
let aFn: boxedFn = createClosure(10);
let myInt: uint = aFn.theFn();
assert myInt == 10;
}
Pourquoi est-ce une fuite de mémoire?