import signal
import gc
from gi.repository import Gst, Gtk, GLib

Gst.init([])

uri = "file:///home/user/Desktop/a.ogg"

# Checked using: GOBJECT_DEBUG=instance-count python a.py
# Using Gtk inspector: shift+ctrl+i -> Statistics -> sort by self
#
# Leaking per iteration:
#    1 GstGhostPad, 1 GstProxyPad

i = 0

def create_playbin():
    global i

    i += 1
    print(i)
    bin_ = Gst.ElementFactory.make('playbin', None)
    bin_.set_property('uri', uri)
    bin_.set_state(Gst.State.PLAYING)
    bin_.get_state(2 ** 64 - 1)
    bin_.set_state(Gst.State.NULL)
    bin_.get_state(2 ** 64 - 1)
    return True

GLib.unix_signal_add(0, signal.SIGINT, Gtk.main_quit)
GLib.idle_add(create_playbin)
w = Gtk.Window()
w.show_all()
Gtk.main()
