@@ -72,14 +72,14 @@ fn setup_clock(window: &Window, document: &Document) -> Result<(), JsValue> {
72
72
) ) ;
73
73
}
74
74
75
- // The instances of `Closure` that we created will invalidate their
76
- // corresponding JS callback whenever they're dropped, so if we were to
77
- // normally return from `run ` then both of our registered closures will
78
- // raise exceptions when invoked.
75
+ // The instance of `Closure` that we created will invalidate its
76
+ // corresponding JS callback whenever it is dropped, so if we were to
77
+ // normally return from `setup_clock ` then our registered closure will
78
+ // raise an exception when invoked.
79
79
//
80
- // Normally we'd store these handles to later get dropped at an appropriate
81
- // time but for now we want these to be global handlers so we use the
82
- // `forget` method to drop them without invalidating the closure. Note that
80
+ // Normally we'd store the handle to later get dropped at an appropriate
81
+ // time but for now we want it to be a global handler so we use the
82
+ // `forget` method to drop it without invalidating the closure. Note that
83
83
// this is leaking memory in Rust, so this should be done judiciously!
84
84
a. forget ( ) ;
85
85
@@ -106,5 +106,7 @@ fn setup_clicker(document: &Document) {
106
106
. dyn_ref :: < HtmlElement > ( )
107
107
. expect ( "#green-square be an `HtmlElement`" )
108
108
. set_onclick ( Some ( a. as_ref ( ) . unchecked_ref ( ) ) ) ;
109
+
110
+ // See comments in `setup_clock` above for why we use `a.forget()`.
109
111
a. forget ( ) ;
110
112
}
0 commit comments