1# Test btree interaction with the garbage collector.
2
3try:
4    import btree, uio, gc
5except ImportError:
6    print("SKIP")
7    raise SystemExit
8
9N = 80
10
11# Create a BytesIO but don't keep a reference to it.
12db = btree.open(uio.BytesIO(), pagesize=512)
13
14# Overwrite lots of the Python stack to make sure no reference to the BytesIO remains.
15x = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
16
17# Write lots of key/value pairs, which fill up the DB and also allocate temporary heap
18# memory due to the string addition, and do a GC collect to verify that the BytesIO
19# is not collected.
20for i in range(N):
21    db[b"thekey" + str(i)] = b"thelongvalue" + str(i)
22    print(db[b"thekey" + str(i)])
23    gc.collect()
24