Python value delivery problem and memory management mechanism

Source: Internet
Author: User

1) Value transfer problem

Whether the python is "value passing" or "reference passing" depends primarily on the object being mutable. 1) Function Reference: • Basic data type: int, float, str; Ganso is a non-mutable object, and a copy of "original value" is passed. The list, dictionary, class, class instances are mutable objects, and the variable copy (a=b) in the variable copy Python is passed as the same as Kind of truth, immutable objects are actually copied, whereas mutable objects simply pass a "reference" example: a = 1 B = A, at which time changing the value of a does not change the value of B

2) Memory mechanism

1) variable values are stored in memory • Basic data types: int, str, float, etc., the same value is assigned to different variables, the memory address is consistent;        • Lists, Ganso, dictionaries, the same values are assigned to different variables, the memory address is an example of inconsistency: a = 1 b = 1 ID (a) =id (b) This is a = [up] b = [up] ID (a) = ID (b) This is not true 2) memory management mechanism • Reference count: Trace objects in memory when an object is created, a reference count is created, and when the object is no longer needed, the object's reference count is 0 o'clock, and it is garbage collected. • Memory pool: not currently discussed


This article from "Kong Love to Eat fish" blog, declined reprint!

Python value delivery problem and memory management mechanism

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.