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
+18.6k Golang : Logging with logrus
+10.3k Golang : Print how to use flag for your application example
+8.8k Golang : Find duplicate files with filepath.Walk
+6.6k Golang : Spell checking with ispell example
+30.6k Golang : Generate random string
+8.6k PHP : How to parse ElasticSearch JSON ?
+30.5k Golang : How to redirect to new page with net/http?
+9.8k Golang : How to extract video or image files from html source code
+9.6k Mac OSX : Get a process/daemon status information
+12.3k Golang : Detect user location with HTML5 geo-location
+51.6k Golang : Disable security check for HTTPS(SSL) with bad or expired certificate
+36.3k Golang : Smarter Error Handling with strings.Contains()