refactor(go)!: 分离练习区与独立项目区

- 将现有练习及 module 文件迁移至 go/practice,保持代码和依赖不变
- 新增 go/projects 项目区说明,更新目录约定与开发命令

BREAKING CHANGE: Go 练习命令需改在 go/practice 目录下执行
This commit is contained in:
2026-10-15 22:26:57 +08:00
parent 86f6eb39b2
commit d375463de5
21 changed files with 91 additions and 33 deletions
+34
View File
@@ -0,0 +1,34 @@
package main
import (
"fmt"
"runtime"
)
var retained [][]byte // 全局变量,用来保持对象可达
func printMemory(stage string) {
var m runtime.MemStats
runtime.ReadMemStats(&m)
fmt.Printf("%s: HeapAlloc=%d MiB, TotalAlloc=%d MiB\n",
stage,
m.HeapAlloc/1024/1024,
m.TotalAlloc/1024/1024)
}
func main() {
runtime.GC()
printMemory("开始")
for i := 0; i < 20; i++ {
block := make([]byte, 1024*1024) // 每次创建约 1 MiB 的底层数组
block[0] = byte(i)
retained = append(retained, block)
}
printMemory("分配后")
retained = nil // 程序不再持有这些数组
runtime.GC()
printMemory("GC 后")
}