Golang : Reclaim memory occupied by make() example
Problem :
You have allocated some memory for buffer via the make()
function and you want to reclaim back the occupied memory after done using the buffer. How to do that?
Solution :
For example :
buffer := make([]byte, 1024)
or
buffer := make([][]int, row)
to reclaim back the memory, simply do :
buffer = nil
Golang's garbage collector will automatically free up the memory or you can trigger garbage collection manually as well with runtime/debug.FreeOSMemory()
References :
https://www.socketloop.com/tutorials/golang-how-to-get-garbage-collection-data
https://www.socketloop.com/tutorials/golang-when-to-use-make-or-new
See also : Golang : When to use make or new?
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+2.3k Python : Convert(cast) bytes to string example
+1.2k Golang : Calculate a pip value and distance to target profit example
+9.9k Golang : Use regular expression to validate domain name
+2.5k Golang : Test input string for unicode example
+10.1k Golang : How to get time from unix nano example
+3.2k Golang : Generate human readable password
+5.7k Golang : Read XML elements data with xml.CharData example
+3.9k Golang : How to generate Code 39 barcode?
+6.5k Golang : Normalize unicode strings for comparison purpose
+8.6k Golang : Read large file with bufio.Scanner cause token too long error
+4.6k Golang : How to use Gorilla webtoolkit context package properly
+2.4k Golang : Get S3 or CloudFront object or file information