Index: pyatspi/accessible.py
===================================================================
--- pyatspi/accessible.py	(revision 965)
+++ pyatspi/accessible.py	(working copy)
@@ -589,6 +589,30 @@
     target.ref()
     return target._narrow(Accessibility.Accessible)
 
+  def __del__(self):
+    '''
+    Unrefence the instance when Python GCs it.
+    '''
+    try:
+      self.unref()
+      self.unref()
+    except Exception:
+      pass
+
+class _UnrefMixin(object):
+  '''
+  This mixin addresses the issue we have with unreferencing non-primitives.
+  '''
+  def __del__(self):
+    '''
+    Unrefence the instance when Python GCs it. Why do we need this twice?
+    '''
+    try:
+      self.unref()
+      #self.unref()
+    except Exception:
+      pass
+
 # 1. mix the exception handlers into all queryable interfaces
 map(_mixExceptions, constants.ALL_INTERFACES)
 # 2. mix the exception handlers into other Accessibility objects
@@ -600,3 +624,6 @@
 _mixInterfaces(Accessibility.Accessible, constants.ALL_INTERFACES)
 # 5. mix Relation class
 _mixClass(Accessibility.Relation, _RelationMixin)
+# 6. mix in neccessary unrefs
+for cls in (Accessibility.StateSet,):
+  _mixClass(cls, _UnrefMixin)
