vefbk.blogg.se

Golang free memory
Golang free memory











golang free memory

The memory is a big thing but there are two big chunks of memory that are relevant to us right now, the stack and the heap. Now in order to discuss how space is de-allocated, we got to discuss a little bit about where space store in memory. When you have to memory deallocation this space in a timely fashion. how we’re going to use it my space we’ve got Val number of the gig in my memory system. You have to say “Look this variable memory is now free, ” because otherwise you would eventually use up all your variable space and you might think well. So, if you have to deallocate this memory. It means once a particular function call ends you no longer need the space for the Val that it was using.

golang free memory

if you will get a new variable Val allocated and so you’ll have all these variable spaces allocated in memory and really you don’t need them anymore. Actually every time if you don’t deallocate it, you’ll execute, every time you execute this function. because the Val goes away after the function completes the Val goes away it’s going to allocate it again it should go away, you want it to go away. if you call this function f 100 times, then it’s going to allocate 100 different spaces for this variable Val right. It declares a variable Val, var Val = 4, so the process when it runs it has to allocate a memory location for Val to hold it. So for an example, you look at following the piece of code. So, when you’re done using your variable value, you want to be able to say “Oh that space is now free and it can be used for other purposes.” So, that’s memory deallocation, when you make memory space available for other purposes.Īpart from that, you eventually will run out of memory and your machine. If it’s an integer value, there has to be some allocated space dedicated to holding that integer and at some point, that space has to be deallocated.

#Golang free memory code#

that means if you declare a variable once and your code is running your space needs to allocate somewhere in memory for that variable. The variables after a long time have to be deallocated in memory. Variables, they are all referring to some data somewhere in memory. In this post, we’ll discuss the deallocating variable’s memory and how they are referenced.













Golang free memory