我正在try 使用Valgrind this blog post检测Rust 程序中的内存泄漏.我的源代码很简单:
#![feature(alloc_system)]
extern crate alloc_system;
use std::mem;
fn allocate() {
let bad_vec = vec![0u8; 1024*1024];
mem::forget(bad_vec);
}
fn main() {
allocate();
}
我预计对mem::forget()
的调用会产生一个Valgrind能够发现的内存泄漏.然而,当我运行Valgrind时,它报告说不可能出现泄漏:
[memtest]> cargo run
Compiling memtest v0.1.0 (file:///home/icarruthers/memtest)
Finished dev [unoptimized + debuginfo] target(s) in 0.28s
Running `target/debug/memtest`
[memtest]> valgrind target/debug/memtest
==18808== Memcheck, a memory error detector
==18808== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==18808== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info
==18808== Command: target/debug/memtest
==18808==
==18808==
==18808== HEAP SUMMARY:
==18808== in use at exit: 0 bytes in 0 blocks
==18808== total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==18808==
==18808== All heap blocks were freed -- no leaks are possible
==18808==
==18808== For counts of detected and suppressed errors, rerun with: -v
==18808== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
我升级到最新的夜间版本(1.29.0-nightly(6a1c0637c 2018-07-23)).
我错过了什么?