-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlecture_13.py
More file actions
65 lines (48 loc) · 1.23 KB
/
lecture_13.py
File metadata and controls
65 lines (48 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# loading gc
import gc
# get the current collection
# thresholds as a tuple
# print("Garbage collection thresholds:",
# gc.get_threshold())
# collected = gc.collect()
# print("Garbage collector: collected",
# "%d objects." % collected)
# x = [1, 2, 3]
# y = [4, 5, 6]
# x.append(y)
# y.append(x)
# # Prints Garbage collector
# collected = gc.collect()
# # as 0 object
# print("Garbage collector: collected",
# "%d objects." % collected)
i = 0
# create a cycle and on each iteration x as a dictionary
# assigned to 1
def create_cycle():
x = { }
x[i+1] = x
print(x)
# lists are cleared whenever a full collection or
# collection of the highest generation (2) is run
collected = gc.collect() # or gc.collect(2)
print("Garbage collector: collected %d objects." % (collected))
print("Creating cycles...")
for i in range(10):
create_cycle()
collected = gc.collect()
print("Garbage collector: collected %d objects." % (collected))
# Create some objects
obj1 = [1, 2, 3]
obj2 = {"a": 1, "b": 2}
obj3 = "Hello, world!"
gc.disable()
# c = gc.collect()
# print(c)
# Delete references to objects
del obj1
del obj2
del obj3
# Force a garbage collection
# c = gc.collect()
# print(c)