What is the difference in the memory management of Mutable and Immutable Data Structures in Python Programming Language?
2 Answers 2
The Python Language Specification does not say anything about Memory Management at all, so it obviously also doesn't say anything about Memory Management of Mutable Data Structures nor does it say anything about Memory Management of Immutable Data Structures.
Every Python Implementation is free to manage their memory however they wish. For example, some use Reference Counting, some use a Tracing Garbage Collector, some use both, some don't have their own Memory Manager at all and rely on the underlying host platform.
There is nothing in the Python Language Specification that would force implementors to treat Mutable and Immutable Data Structures the same, there is also nothing in the Python Language Specification that would force implementors to treat Mutable and Immutable Data Structures differently.
Comments
Mutable is a fancy way of saying that the internal state of the object is changed/mutated.
So, the simplest definition is: An object whose internal state can be changed is mutable. On the other hand, immutable doesn’t allow any change in the object once it has been created.
You can find out more here.
There isn't really much difference, just the way the data is compiled. If your on an older machine/OS, it might take longer to compile your data structure or use a different algorithm to save time.
tuple, all the numeric types (int,float,complex,fractions.Fraction,decimal.Decimal),str,bytes,frozenset.... maybe more