Index: pyatspi/registry.py
===================================================================
--- pyatspi/registry.py	(revision 969)
+++ pyatspi/registry.py	(working copy)
@@ -1,5 +1,5 @@
 '''
-Registry that hides some of the details of registering for AT-SPI events and
+Registrystry that hides some of the details of registering for AT-SPI events and
 starting and stopping the main program loop.
 
 @todo: PP: when to destroy device listener?
@@ -41,6 +41,8 @@
 import utils
 import constants
 import event
+import weakref
+import accessible
 
 class _Observer(object):
   '''
@@ -258,19 +260,60 @@
     else:
       return None
 
-  def notifyEvent(self, ev):
+  def notifyEvent(self, raw_event):
     '''
     Notifies the L{Registry} that an event has occurred. Wraps the raw event 
     object in our L{Event} class to support automatic ref and unref calls.
     Aborts on any exception indicating the event could not be wrapped.
     
-    @param ev: AT-SPI event signal (anything but keyboard)
-    @type ev: Accessibility.Event
+    @param raw_event: AT-SPI event signal (anything but keyboard)
+    @type raw_event: Accessibility.Event
     '''
-    # wrap raw event so ref counts are correct before queueing
-    ev = event.Event(ev)
+    ev = event.Event(raw_event)
+
+    ref_later = weakref.WeakKeyDictionary()
+    for attrib in ('source', 'any_data', 'host_application'):
+      acc = getattr(ev, attrib)
+      try:
+        acc.dont_unref = True
+      except AttributeError:
+        continue
+      
+      try:
+        ref_later[acc] = None
+      except TypeError:
+        # Weak referencing of corba objects is not supported by this 
+        # version of pyorbit. Just do a ref() here.
+        try:
+          acc.ref()
+        except:
+          pass
+
+      # The frame keeps a reference to the last item if we don't 
+      # explicitly delete this.
+      del acc
+
     self.registry.handleEvent(ev)
 
+    del ev
+
+    # Since the raw event intance is referenced by the current frame, there
+    # is no real way of removing it, so we have to delete the fields that
+    # might have Accessible objects.
+    for attrib in ('source', 'any_data'):
+      try:
+        delattr(raw_event, attrib)
+      except AttributeError:
+        continue
+
+    for acc in ref_later.keys():
+      try:
+        acc.ref()
+      except:
+        pass
+      else:
+        acc.dont_unref = False
+
 class Registry(object):
   '''
   Wraps the Accessibility.Registry to provide more Pythonic registration for
Index: pyatspi/accessible.py
===================================================================
--- pyatspi/accessible.py	(revision 970)
+++ pyatspi/accessible.py	(working copy)
@@ -359,7 +359,7 @@
   @type SLOTS: tuple
   '''
   SLOTTED_CLASSES = {}
-  SLOTS = ('_icache', '_property_cache', '_user_data')
+  SLOTS = ('_icache', '_property_cache', '_user_data', 'dont_unref')
   
   def __new__(cls):
     '''
@@ -401,7 +401,8 @@
     we're caching properties. 
     '''
     try:
-      self.unref()
+      if not self.dont_unref:
+        self.unref()
     except Exception:
       pass
     
Index: pyatspi/event.py
===================================================================
--- pyatspi/event.py	(revision 969)
+++ pyatspi/event.py	(working copy)
@@ -137,13 +137,6 @@
     self.type = EventType(event.type)
     self.detail1 = event.detail1
     self.detail2 = event.detail2
-    # store the event source and increase the reference count since event 
-    # sources are borrowed references; the AccessibleMixin automatically
-    # decrements it later
-    try:
-      event.source.ref()
-    except AttributeError:
-      pass
     self.source = event.source
 
     # process any_data in a at-spi version independent manner
@@ -163,16 +156,6 @@
       self.host_application = details.host_application
       self.source_name = details.source_name
       self.source_role = details.source_role
-    try:
-      # if we received an accessible, be sure to increment the ref count
-      self.any_data.ref()
-    except AttributeError:
-      pass
-    try:
-      # if we received a host application, be sure to increment the ref count
-      self.host_application.ref()
-    except AttributeError:
-      pass
 
   def __str__(self):
     '''
