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.

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?

As you see here:

Go is fully garbage-collected and provides fundamental support for concurrent execution and communication.

So you don't have to care about memory allocation.

In Go, unlike in C and C++, but like in Java, memory is managed automatically by a garbage collector.

There is no delete to call.

Off-topic:

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.

You must delete, otherwise you have memory leak.