Datsik
Datsik

Reputation: 14824

Do variables in a loop get garbage collected or do they stay in memory?

Does the variable in this bit of code get garbage collected after the loop finishes or do I have X amount of sSteamId variables floating in memory forever?

If it does, how can I do this more efficiently? I only need sSteamId long enough to convert an int to a string and then append it to a byte, then it's no longer needed

for _, id := range steamIds {
        sSteamId := strconv.Itoa(id)
        requestURI = append(requestURI, ","+sSteamId...)
}

Upvotes: 2

Views: 667

Answers (1)

Will Hartung
Will Hartung

Reputation: 118774

They'll get GC'd as any references to them are lost with each iteration.

Upvotes: 2

Related Questions