diff --git a/gdk/quartz/gdkeventloop-quartz.c b/gdk/quartz/gdkeventloop-quartz.c
index 97a7e39..f549f3e 100644
--- a/gdk/quartz/gdkeventloop-quartz.c
+++ b/gdk/quartz/gdkeventloop-quartz.c
@@ -642,7 +642,7 @@ gdk_event_check (GSource *source)
    * autorelease_pool is static and releasing a pool will cause all pools
    * allocated inside of it to be released as well.
    */
-  if (current_loop_level == 0 && g_main_depth() == 0)
+  if (current_loop_level == 0 && g_main_depth() == 0 && getting_events == 0)
     {
       if (autorelease_pool)
         [autorelease_pool drain];
@@ -703,6 +703,7 @@ poll_func (GPollFD *ufds,
   NSEvent *event;
   NSDate *limit_date;
   gint n_ready;
+  static gint last_depth;
 
   n_ready = select_thread_start_poll (ufds, nfds, timeout_);
   if (n_ready > 0)
@@ -716,10 +717,18 @@ poll_func (GPollFD *ufds,
     limit_date = [NSDate dateWithTimeIntervalSinceNow:timeout_/1000.0];
 
   getting_events++;
+  last_depth = getting_events;
   event = [NSApp nextEventMatchingMask: NSAnyEventMask
 	                     untilDate: limit_date
 	                        inMode: NSDefaultRunLoopMode
                                dequeue: YES];
+  if (last_depth != getting_events)
+    {
+      /* g_print("Skipping collect due to recursion from %d\n", last_depth); */
+      last_depth = getting_events;
+      n_ready = 0;
+    }
+  
   getting_events--;
 
   if (n_ready < 0)
