示例工程 22-object-model-refcount-gc
22-object-model-refcount-gc/01-refcount-experiment/README.md
# 01 · refcount-experiment
**演示**:`sys.getrefcount(obj)` 返回当前引用计数(参数本身会临时 +1);`alias = obj` 让计数从 2 变 3,`del alias` 回到 2。
**运行**:
```sh
uv run python examples/22-object-model-refcount-gc/01-refcount-experiment/refcount_experiment.py
```
**预期输出**(3.12.9):
```text
base: 2
alias: 3
after: 2
```
**依赖**:仅标准库。
**注意**:3.12/3.13 输出 `2/3/2`;3.14 起 `getrefcount` 不再把自身参数计入,输出 `1/2/1`。绝对值会随版本变化,但「别名 +1、删除 -1」稳定;不要用绝对引用计数做逻辑判断。