[][src]Function wasm_bindgen::externref_heap_live_count

pub fn externref_heap_live_count() -> u32

Get the count of live externrefs / JsValues in wasm-bindgen's heap.

Usage

This is intended for debugging and writing tests.

To write a test that asserts against unnecessarily keeping anrefs / JsValues alive:

What is Counted

Note that this only counts the owned externrefs / JsValues that end up in wasm-bindgen's heap. It does not count borrowed externrefs / JsValues that are on its stack.

For example, these JsValues are accounted for:

This example is not tested
#[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:

This example is not tested
#[wasm_bindgen]
pub fn my_other_function(this_is_not_counted: &JsValue) {
    // ...
}