RUVIDEO
Поделитесь видео 🙏

Memory Allocation to Functions and Garbage Collection in Python | Lesson 30 |Python |Learning Monke

#pytho #learningmonke #pythoncodin #placement #pythontutorial #pythoncours #pythonforbeginner #pythonfordatascienc #pythonfullcours #pythonprogrammin #pythonfreecourse
Memory Allocation to Functions and Garbage Collection in Python
In this class, we discuss Memory Allocation to Functions and Garbage Collection in Python.
Memory Allocation to Functions
The reader should have prior knowledge of how memory is allocated to variables in python. Click here.
The memory allocation concept is very important to understand recursive function execution.
The discussion about recursive function is made in our next classes.
Python assigns some set of space to execute a program. The list is given in the below diagram.
Code space: The high-level code is converted to machine-level instructions, and the converted instructions are placed in RAM.
Global space: The programs global variables are given memory in the global space given to the program.
Heap space: Objects in the program are assigned memory in heap space.
Stack space: Function variables are provided memory in stack space.
Let’s take an example and understand how the memory is allocated during the execution of a program.
In the above program, we have two functions, f and f1.
The program starts execution from line a=1.
What happens when the line a=1 executed?
In a =1. 1 is an integer object. This integer object is assigned memory in heap space.
This a=1 is a global variable. Therefore, the reference of the variable is maintained in global space.
In our example, integer object one is assigned memory at location 50. shown in the above memory diagram.
In the memory diagram shown above. It was mentioned a=50 in global space. This a= 50 means a is referencing to memory location 50.
After execution of line a=1, the next line is f(a). function f is called.
What happens in the memory after calling the function f.
To execute the function, f. python will assign some memory in the stack. The stack memory is used to maintain the local variables of the function.
Function f had two variables, x and z. x is now a reference to memory location 50.
Because variable a is passed as an argument to the function. These basics are explained in the function concept. Click here.
Function f assigned value 2 for variable z. value two is set a memory location 40.
Variable z has maintained a reference to memory location 40.
After execution of function f. the memory assigned to the function is deleted.
Now the stack is empty. But still, object 2 is present in memory location 40. and no variable is referencing the integer object 2.
Garbage collection comes into the picture at this stage.
Garbage Collection
The garbage collection program will check the objects that are no more in use.
The garbage collection program identifies the objects, not in use and removes them from the heap.
In our example, integer object two is not referenced by any variable after completing the function.
After removing the integer object, we can use that memory for another object.
The need for garbage collection is to remove the unused objects from memory.
Now the function f1 is called. Memory for function f1 is assigned in the stack space.
Variables y and k maintain reference now. And after completion of the function, f1. The memory allocated will be removed.
Take one more example and understand the concept better.
In the above program, variable a and variable b are global variables.
Variable x and variable z are local variables to the function f.
In the function, f. variable b is used.
First, the variable is searched in function local variables memory.
Suppose the variable is not found in local memory. Then function checks in global variable memory.


Link for playlists:
https://www.youtube.com/channel/UCl8x4Pn9Mnh_C1fue-Yndig/playlists


Link for our website: https://learningmonkey.in

Follow us on Facebook @ https://www.facebook.com/learningmonkey

Follow us on Instagram @ https://www.instagram.com/learningmonkey1/

Follow us on Twitter @ https://twitter.com/_learningmonkey

Mail us @ [email protected]

Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «Memory Allocation to Functions and Garbage Collection in Python | Lesson 30 |Python |Learning Monke», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.

Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.

Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!

Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.