How to make Go routines release their used memory

Thanks for tracking this down.

I tried to import the package like this:

import 	(
  "fmt"
  "time"
  "sort"
  "sync"
  "math"
  "math/bits"
  "runtime"
  "github.com/korovkin/limiter"
)

but get this message:

go-projects> go build twinprimes_ssoznew2.go
twinprimes_ssoznew2.go:44:3: no required module provides package github.com/korovkin/limiter: working directory is not part of a module

I went to the github website, but there are no instructions on how to import it.
Can you tell me exactly what I need to do. Remember, I’m new to Go.

you have to use go modules - https://blog.golang.org/using-go-modules

This is new with go1.16 and makes go a bit less friendly to new users.
Now you are required to create a go.mod file next to your program file. This file and its sibling go.sum is the way go tracks the version and dependency of external modules.

To create the go.mod file simply execute the instruction go mod init twinprimes_ssoznew2. Then call go mod tidy and it will automatically download the external modules if needed and create the go.sum file that contains the hashes of the external modules.

Whenever you add a new external package to your program, simply call go mod tidy again. It will download the package and update the go.mod file.

There are other ways to do it, sometime simpler, but that is easy to remember and works every time.

You put the name of the program/command you create as argument to the go mod init command. You can then call go install and it will generate an executable binary with that name. The binary will be stored in the directory specified in the GOBIN environment variable which by default is $GOPATH/bin. If you add $GOBIN to your path environment, you will be able to call the program directly as twinprimes_ssoznew2.

When you create your own module to be published and used by others, you put the module import name as argument of the go mod init instruction (e.g. go mod init github.com/toto/mymodule).

1 Like

Great and useful information, thanks!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.