How to deallocate memory in go?

huangapple go评论70阅读模式
英文:

How to deallocate memory in go?

问题

我有一个结构体:

type xyz struct {
    x int
    y string
}

func f(){
    x := new(xyz) //分配内存
}

但是我找不到在Go语言中释放它的任何方法。

  • 在Go语言中不需要释放它吗?
  • 有没有关于Go语言内存分配/释放的有用文档?
英文:

I have a structure:

type xyz struct {
    x int
    y string
}

func f(){
    x := new(xyz) //allocating memory
}

But I cannot find any method to deallocate it in go.

  • Is it not needed to deallocate it in golang?
  • Is there any useful document for how memory allocation/deallocation happens in go?

答案1

得分: 16

Go是一种具有垃圾回收功能的语言,你不需要手动释放内存。

关于Go语言中内存分配和释放的文章:

  1. 垃圾回收
  2. 堆和栈分配
  3. 关于分配优化的讨论
  4. 变量分配
英文:

Go is garbage collected language. You do not have to deallocate memory.

Articles on memory allocation and deallocation in Go.

  1. Garbage collection
  2. Heap and stack allocation
  3. Discussion on allocation optimization
  4. Variable allocation

huangapple
  • 本文由 发表于 2014年11月21日 18:41:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/27059403.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定