summaryrefslogtreecommitdiff
path: root/test/isurface_get_data_memleak.py
blob: 5a30c1e193b4160a4f23afa80f5936ca3330083e (plain)
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
#!/usr/bin/env python
"""test cairo.ImageSurface.get_data() for a memory leak
"""

import array
import resource
import tempfile

import cairo


pagesize = resource.getpagesize()

if not (cairo.HAS_IMAGE_SURFACE and cairo.HAS_PNG_FUNCTIONS):
  raise SystemExit ('cairo was not compiled with ImageSurface and PNG support')

width, height = 32, 32

while True:
  for i in range(100000):
    surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)
    ctx = cairo.Context(surface)
    data = surface.get_data()
    b = memoryview(memoryview(data))
    del surface
    del ctx
    b = bytes(data)

    surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)
    #ctx = cairo.Context(surface)
    b = bytes(surface.get_data())

  print(resource.getrusage(resource.RUSAGE_SELF).ru_maxrss * pagesize)