![]() ![]() Garbage Collection is used to ensure that memory on the heap is released occasionally. However, memory that is allocated on the heap is not released immediately when it is no longer referenced. Memory that is allocated on the stack is released immediately when it is no longer referenced. So why is it important to understand the differences between how memory is managed on the stack and on the heap? List2.Add(6) //add another item to list2 – because it is a reference type, both list1 and list2 are affected both list1 and list2 are pointing to the same memory location on the heap List2 = list1 //list2 receives a copy of the value of list1 – however in this case the copy is only a copy of the reference ![]() List1 = new ArrayList() //new ArrayList() allocates memory on the heap and points to the referenceĪrrayList list2 span class=”comment”>//this declaration allocaties memory on the stack In this first video I will be discussing memory regions we must know about as Rust dev. The following code sample shows that Value Types directly contain their own data.ĪrrayList list1 //this declaration allocates memory on the stack This is the first video in a series of videos about memory management.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |