[−][src]Function wasm_bindgen::externref_heap_live_count
pub fn externref_heap_live_count() -> u32
Get the count of live externref
s / JsValue
s in wasm-bindgen
's heap.
Usage
This is intended for debugging and writing tests.
To write a test that asserts against unnecessarily keeping anref
s /
JsValue
s alive:
-
get an initial live count,
-
perform some series of operations or function calls that should clean up after themselves, and should not keep holding onto
externref
s /JsValue
s after completion, -
get the final live count,
-
and assert that the initial and final counts are the same.
What is Counted
Note that this only counts the owned externref
s / JsValue
s that end up in
wasm-bindgen
's heap. It does not count borrowed externref
s / JsValue
s
that are on its stack.
For example, these JsValue
s are accounted for:
#[wasm_bindgen] pub fn my_function(this_is_counted: JsValue) { let also_counted = JsValue::from_str("hi"); assert!(wasm_bindgen::externref_heap_live_count() >= 2); }
While this borrowed JsValue
ends up on the stack, not the heap, and
therefore is not accounted for:
#[wasm_bindgen] pub fn my_other_function(this_is_not_counted: &JsValue) { // ... }