示例
Release managed root directories and retained loader memory by coordinating Zeitwerk unload and unregister lifecycle calls
sha256:75407f503d18673b17265d62c127a0e8fb4349c235b2832a4d25826f1d56f9fa
PUBLISHED
L3_CONTRACT_PASS
MIT-0
案例
- 目标
- Release managed root directories and retained loader memory by coordinating Zeitwerk unload and unregister lifecycle calls HOW
- 包
- zeitwerk 2.8.3
- 环境
- ruby
- 创建时间
- 2026-08-17T01:23:41Z
常见的想当然
Calling loader.unload completely tears down a Zeitwerk loader and releases its root directories for re-use by new loaders or for garbage collection.
这是本样本作者记下的、开发者或模型在此处通常会有的预期。下面的契约才是真正运行过的东西。
契约
- assert calling loader.unload clears constants and autoloads but retains the loader in Zeitwerk::Registry.loaders and Zeitwerk::Loader.all_dirs, blocking any new loader from managing that root directory with Zeitwerk::Error until loader.unregister is explicitly called
- assert calling loader.unregister without calling loader.unload leaves Ruby VM autoload triggers registered on namespace constants but disconnects loader tracking
- assert calling loader.unregister removes the loader from Zeitwerk::Registry.loaders and permits full garbage collection of unreferenced loader instances
- assert calling loader.unregister on a loader created with Zeitwerk::Loader.for_gem purges the cached entry from Zeitwerk::Registry.gem_loaders_by_root_file so subsequent for_gem calls construct a new instance
- assert executing loader.unload followed by loader.unregister completely purges constants, loaded features, directory registrations, and global references
- assert zeitwerk 2.8.3 is pure Ruby with zero runtime dependencies and zero C extensions
文件
- Gemfile
- Gemfile.lock
- NOTES.md
- csx.json
- fixtures/app/models/post.rb
- fixtures/app/models/user.rb
- fixtures/fake_gem/lib/fake_gem.rb
- fixtures/fake_gem/lib/fake_gem/version.rb
- src/lifecycle_manager.rb
- test/contract.rb
下载已验证的构件 (tar.gz) — 契约实际运行的那些字节
原始种子者
验证回执
- ruby 3 · CONTAINER_RUN · compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS · rubygems@1 · 2026-08-17 · ed25519:d91480838ac982c9