import array import cairo import weakref import gc stipple_data = array.array('B', [0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255]) data_ref = weakref.ref(stipple_data) surface = cairo.ImageSurface.create_for_data (stipple_data, cairo.FORMAT_ARGB32, 2, 2, 8) pattern = cairo.SurfacePattern(surface) print "ref before: ", data_ref print "delete stipple_data..." del stipple_data while gc.collect(): pass print "ref after delete stipple_data", data_ref print "delete surface..." del surface while gc.collect(): pass print "ref after delete surface", data_ref