Go Built-In Function new: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
No edit summary
Line 16: Line 16:
ptr = new(some_type)
ptr = new(some_type)
</pre>
</pre>
We don't have to worry about de-allocating memory allocated with <tt>new()</tt>. It is automatically garbage collected.

Revision as of 01:27, 30 March 2016

External

Internal

Overview

The new() built-in function takes a type as argument, allocates memory of the given type and returns a pointer to it.

var ptr *some_type
ptr = new(some_type)

We don't have to worry about de-allocating memory allocated with new(). It is automatically garbage collected.