File: memleak.py

package info (click to toggle)
python-apt 1.4.1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 3,980 kB
  • sloc: cpp: 10,003; python: 7,108; makefile: 107; sh: 27
file content (46 lines) | stat: -rw-r--r-- 967 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/python

import apt
import apt_pkg
import time
import gc
import sys


cache = apt.Cache()

# memleak
for i in range(100):
    cache.open(None)
    print cache["apt"].name
    time.sleep(1)
    gc.collect()
    f = open("%s" % i, "w")
    for obj in gc.get_objects():
        f.write("%s\n" % str(obj))
    f.close()

# memleak
#for i in range(100):
#       cache = apt.Cache()
#       time.sleep(1)
#       cache = None
#       gc.collect()

# no memleak, but more or less the apt.Cache.open() code
for i in range(100):
    cache = apt_pkg.Cache()
    depcache = apt_pkg.DepCache(cache)
    records = apt_pkg.PackageRecords(cache)
    list = apt_pkg.SourceList()
    list.read_main_list()
    dict = {}
    for pkg in cache.packages:
        if len(pkg.version_list) > 0:
            dict[pkg.name] = apt.package(cache, depcache,
                                         records, list, None, pkg)

    print cache["apt"]
    time.sleep(1)

    gc.collect()