Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Analysis on the problems of cyclic reference and tag removal in python

2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces the problem analysis of circular citation and tag removal in python, which is very detailed and has a certain reference value. Friends who are interested must read it!

=

1 in the case of circular references, reference counting is not good, and it is necessary to use tags to clear the harm of circular references: it will cause memory overflow, because circular reference count can not be zero solution: tag cleanup 2 on the efficiency of tag removal (low) the reference count is increased by 1 at a time, and the value should be recycled after decreasing to 0 Then there is a problem here: the garbage collection mechanism of cpython is not running all the time, it is run at regular intervals, and there will be an efficiency problem here. In order to ensure efficiency, cpython uses generation-by-generation recycling, which improves the efficiency of generation-by-generation recycling: 1 Old Age: the frequency of commonly used data scanned in old times (such as scanning once an hour) may be relatively low. Some old data may still be in use, so the scanning is relatively low. 2 younger generations: new data may be scanned more frequently when they are young (for example, once every 5 minutes), because some new data may be abandoned as soon as they are generated. In this way, we can clean up the memory space in time about mark removal: first of all, let's talk about the concept of variables: 1 variable name: no storage value, just point to a memory address 2 assignment symbol 3 variable value: this is the place where the data is stored, the variable name is stored in the stack, and the variable value is placed in the heap where we can only manipulate the heap, that is, the variable value. You can't control where the variable name is stored, for example: X = 1 x = 2 x finally equals 2, because the memory address that x points to changes the value through the variable name, and it has a marking process, and the object that exists in the stack area is called the GC Roots object, which scans all the contents in the stack area (variable name). All objects directly or indirectly accessed by objects in the stack area are marked as living objects, and the rest are non-living objects, which should be cleared, such as: L1 = [1] L2 = [2] l1.append (L2) l2.append (L1) del L1 del L2 what is an GC Roots reachable object? Through the stack area (variable name) can reach (access) the object, called GC Roots reachable object, L1 is a GC Roots,del and pointed to the memory address to unbind, L1 there is no reference count the above is "python circular references and tag removal of the problem analysis" of this article, thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report