Skip to content

Conversation

@wike2019
Copy link
Contributor

为什么需要 category := category:

在 Go 1.22 之前,循环变量 category 在每次迭代中使用同一个内存地址
如果直接使用 &category,所有指针都会指向最后一次迭代的值
虽然 Go 1.22+ 已修复此问题(每次迭代创建新变量),但显式创建新变量
可以保证代码在所有 Go 版本中都能正确工作,提高可移植性
代码意图更明确:明确表示我们要为每个节点创建独立的内存空间

@pixelmaxQm
Copy link
Collaborator

有两个小问题
1 变量名称尽量改一下
2 注释清理一下

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants