Skip to content

Instantly share code, notes, and snippets.

// Hat tip to Adam Klein for an explanation.
// v8's code generation goes through phases that roughly correspond to:
// Parse -> Analyze -> Generate Code
// During Parse/analyze, v8 tracks which variables in scope are used by closures in that scope
// All closures declared in a function keep references to any variables used by any closure
// in that function.
// In the following example, each function returned by retainTooMuch will retain bbz, even though
// the returned closure doesn't reference that variable, because another closure in the same scope
// did reference bbz.
function retainTooMuch() {
use std::fs::File;
use std::io::{BufReader, Read};
use std::iter::Peekable;
use std::str::Chars;
use std::string::String;
use std::vec::Vec;
#[derive(Debug, PartialEq, Copy, Clone)]
pub struct Location {
offset: u64,