dongyue4964 2016-10-24 10:42
浏览 65
已采纳

Golang新内存分配

I have started programming in Go and I was wondering when new(Object) is used it allocates memory to the size of that object right? If this is the case how do I free this memory once I have finished using the object?

I ask this because in C++ when new is used on an object you can delete the object once there is no longer any need for the object to be stored.

I have been searching to see if Go does have delete or something similar to C++ but I have been unable to find anything.

Any help is much appreciated.

  • 写回答

3条回答 默认 最新

  • double2022 2016-10-24 10:45
    关注

    Go has garbage collection. This means the Go runtime checks in the background if an object or any other variable is not used anymore and if this is the case, frees the memory.

    Also see the Go FAQ: Why is the syntax so different from C? - Why do garbage collection? Won't it be too expensive?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 ansys fluent计算闪退
  • ¥15 有关wireshark抓包的问题
  • ¥15 需要写计算过程,不要写代码,求解答,数据都在图上
  • ¥15 向数据表用newid方式插入GUID问题
  • ¥15 multisim电路设计
  • ¥20 用keil,写代码解决两个问题,用库函数
  • ¥50 ID中开关量采样信号通道、以及程序流程的设计
  • ¥15 U-Mamba/nnunetv2固定随机数种子
  • ¥15 vba使用jmail发送邮件正文里面怎么加图片
  • ¥15 vb6.0如何向数据库中添加自动生成的字段数据。