@@ -30,16 +30,20 @@ pub(crate) type Callback<'lua, 'a> =
30
30
/// [`Context::remove_registry_value`], and instances not manually removed can be garbage collected
31
31
/// with [`Context::expire_registry_values`].
32
32
///
33
- /// Be warned, If you place this into Lua via a `UserData` type or a rust callback, it is *very
34
- /// easy* to accidentally cause reference cycles that the Lua garbage collector cannot resolve.
35
- /// Instead of placing a `RegistryKey` into a `UserData` type, prefer instead to use
36
- /// [`UserData::set_user_value`] / [`UserData::get_user_value`], and instead of moving a RegistryKey
37
- /// into a callback, prefer [`Context::scope`].
33
+ /// Be warned, If you place this into Lua via a `UserData` type or a rust callback and rely on
34
+ /// [`Context::expire_registry_values`], it is *very easy* to accidentally cause reference cycles
35
+ /// that cannot be automatically collected. The Lua garbage collector is not aware of the registry
36
+ /// handle pattern, so holding onto a `RegistryKey` inside Lua may lead to it never being dropped,
37
+ /// and it if it is not droped, [`Context::expire_registry_values`] will never remove the value from
38
+ /// the registry, leading to an uncollectable cycle. Instead of placing a `RegistryKey` into Lua
39
+ /// and relying on it being automatically dropped, prefer APIs which the Lua garbage collector
40
+ /// understands, such as [`UserData::set_user_value`] / [`UserData::get_user_value`] for UserData
41
+ /// types and [`Function::bind`] for callbacks.
38
42
///
39
43
/// [`Context::registry_value`]: struct.Context.html#method.registry_value
40
44
/// [`Context::remove_registry_value`]: struct.Context.html#method.remove_registry_value
41
45
/// [`Context::expire_registry_values`]: struct.Context.html#method.expire_registry_values
42
- /// [`Context::scope `]: struct.Context .html#method.scope
46
+ /// [`Function::bind `]: struct.Function .html#method.bind
43
47
/// [`UserData::set_user_value`]: struct.UserData.html#method.set_user_value
44
48
/// [`UserData::get_user_value`]: struct.UserData.html#method.get_user_value
45
49
pub struct RegistryKey {
0 commit comments