user2079355
user2079355

Reputation: 161

Can overwriting variable name in Python fill memory?

In Python, if I have a variable name and reset it with an object, could that eventually fill memory?

while True:
    a = 'test string'

Upvotes: 1

Views: 1153

Answers (1)

Leo Arad
Leo Arad

Reputation: 4472

Python is allocating memory for objects that created when referencing new variables if they not exist.
In your case, the memory allocation will take place once on the first iteration, and then it will keep referencing the same object in each iteration so it will not allocate the full memory that you have.
This loop can run until you will kill the process without warring about memory space.

Upvotes: 2

Related Questions