From the course: Programming Foundations: Memory, Pointers, and Garbage Collection
Unlock the full course today
Join today to access over 25,200 courses taught by industry experts.
Deallocating memory - Python Tutorial
From the course: Programming Foundations: Memory, Pointers, and Garbage Collection
Deallocating memory
- [Instructor] The releasing of a piece of memory and making it available again is called deallocation. For the stack, this is sort of easy. When a function is done, the stack memory that was holding the variables for the function gets released by the system and pointer of the stack or called stack goes down by one to the previously called function. For the heap, this is slightly more complicated. First of all, the heap memory gets fragmented by this process. When the heap memory is reserved, blocks are reserved in a sequence. Releasing blocks makes the heap fragmented. And this means that finding a memory space for a bigger type can be tough since it may not fit in the gap and the allocator could have to add it to the end or defragment the heap. All of this actually depends on the system and the logic of the allocate of the language that you're using. But this is not all. In some situations, it's easy. For example…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
What is memory?3m 43s
-
(Locked)
Why do we need to manage the memory?3m 19s
-
(Locked)
Stack memory3m 17s
-
(Locked)
Heap memory3m 39s
-
(Locked)
Heap vs. stack memory6m 47s
-
(Locked)
Allocating memory1m 49s
-
(Locked)
Deallocating memory1m 53s
-
(Locked)
Garbage collection6m 50s
-
(Locked)
Actual removing or sweeping2m 48s
-
-
-
-
-