Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons

© 2026 BraveProgrammer. All rights reserved.

  1. Courses
  2. /
  3. Go Programming Bootcamp

Lesson 9 of 60 · Go

Pointers, Allocation, and the Garbage Collector

Duration: 20 minutes

Pointers

This lesson explains the main concept clearly with beginner-friendly examples and background so you can learn why the code works.

Go exposes pointers (*T) but does not allow pointer arithmetic.

var x int = 10
p := &x        // p points to x
fmt.Println(*p) // 10
*p = 20        // changes x to 20

new vs. make

  • new(T) returns a pointer to a zero‑valued T.
  • make allocates and initializes slices, maps, and channels.
p := new(int)    // *int, value 0
s := make([]int, 0, 10) // slice with capacity 10

Garbage Collection (GC)

Go’s GC is concurrent, non‑generational and tuned for low‑latency. You generally do not need to free memory manually; just let references go out of scope.

When to be GC‑friendly

  • Reuse large buffers (bytes.Buffer) instead of allocating per request.
  • Avoid retaining references to huge objects longer than needed.

Info

The runtime package offers runtime.GC() for manual triggers (rarely needed) and runtime.MemStats for introspection.

Previous: Error Handling & DeferNext: Working with Files & I/O