diff --git a/ChangeLog b/ChangeLog index 0d463b6b1b..343a483658 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2007-12-10 Richard Hult + + Merged from trunk: + + * gdk/quartz/gdkdrawable-quartz.c: + (gdk_quartz_drawable_get_context), + (gdk_quartz_drawable_release_context): + * gdk/quartz/gdkeventloop-quartz.c: (gdk_event_prepare), + (gdk_event_check), (gdk_event_dispatch), (poll_func): + * gdk/quartz/gdkwindow-quartz.h: Replace the autorelease pools + used for each drawing context and in prepare, dispatch and poll + with one that exists across each main loop iteration. Fixes leaks + on leopard and protects against future leaks introduce when the + underlying system changes again (bug #492977). + 2007-12-10 Richard Hult Merged from trunk: diff --git a/gdk/quartz/gdkdrawable-quartz.c b/gdk/quartz/gdkdrawable-quartz.c index 7e1172fc0b..7bcda9035c 100644 --- a/gdk/quartz/gdkdrawable-quartz.c +++ b/gdk/quartz/gdkdrawable-quartz.c @@ -687,14 +687,8 @@ gdk_quartz_drawable_get_context (GdkDrawable *drawable, */ if (window_impl->in_paint_rect_count == 0) { - window_impl->pool = [[NSAutoreleasePool alloc] init]; if (![window_impl->view lockFocusIfCanDraw]) - { - [window_impl->pool release]; - window_impl->pool = NULL; - - return NULL; - } + return NULL; } cg_context = [[NSGraphicsContext currentContext] graphicsPort]; @@ -767,15 +761,7 @@ gdk_quartz_drawable_release_context (GdkDrawable *drawable, /* See comment in gdk_quartz_drawable_get_context(). */ if (window_impl->in_paint_rect_count == 0) - { - [window_impl->view unlockFocus]; - - if (window_impl->pool) - { - [window_impl->pool release]; - window_impl->pool = NULL; - } - } + [window_impl->view unlockFocus]; } else if (GDK_IS_PIXMAP_IMPL_QUARTZ (drawable)) CGContextRelease (cg_context); diff --git a/gdk/quartz/gdkeventloop-quartz.c b/gdk/quartz/gdkeventloop-quartz.c index a696a39e75..bb14a13f32 100644 --- a/gdk/quartz/gdkeventloop-quartz.c +++ b/gdk/quartz/gdkeventloop-quartz.c @@ -23,6 +23,7 @@ static GPollFD *pipe_pollfd; static guint n_pollfds; static CFRunLoopSourceRef select_main_thread_source; static CFRunLoopRef main_thread_run_loop; +static NSAutoreleasePool *autorelease_pool; gboolean _gdk_quartz_event_loop_check_pending (void) @@ -56,8 +57,6 @@ gdk_event_prepare (GSource *source, GDK_THREADS_ENTER (); - GDK_QUARTZ_ALLOC_POOL; - *timeout = -1; event = [NSApp nextEventMatchingMask: NSAnyEventMask @@ -68,8 +67,6 @@ gdk_event_prepare (GSource *source, retval = (_gdk_event_queue_find_first (_gdk_display) != NULL || event != NULL); - GDK_QUARTZ_RELEASE_POOL; - GDK_THREADS_LEAVE (); return retval; @@ -82,6 +79,10 @@ gdk_event_check (GSource *source) GDK_THREADS_ENTER (); + if (autorelease_pool) + [autorelease_pool release]; + autorelease_pool = [[NSAutoreleasePool alloc] init]; + if (_gdk_event_queue_find_first (_gdk_display) != NULL || _gdk_quartz_event_loop_check_pending ()) retval = TRUE; @@ -102,8 +103,6 @@ gdk_event_dispatch (GSource *source, GDK_THREADS_ENTER (); - GDK_QUARTZ_ALLOC_POOL; - _gdk_events_queue (_gdk_display); event = _gdk_event_unqueue (_gdk_display); @@ -116,8 +115,6 @@ gdk_event_dispatch (GSource *source, gdk_event_free (event); } - GDK_QUARTZ_RELEASE_POOL; - GDK_THREADS_LEAVE (); return TRUE; @@ -201,8 +198,6 @@ poll_func (GPollFD *ufds, guint nfds, gint timeout_) int n_active = 0; int i; - GDK_QUARTZ_ALLOC_POOL; - if (nfds > 1) { if (!select_thread) { @@ -306,8 +301,6 @@ poll_func (GPollFD *ufds, guint nfds, gint timeout_) n_active ++; } - GDK_QUARTZ_RELEASE_POOL; - return n_active; } @@ -327,6 +320,7 @@ _gdk_quartz_event_loop_init (void) old_poll_func = g_main_context_get_poll_func (NULL); g_main_context_set_poll_func (NULL, poll_func); - + + autorelease_pool = [[NSAutoreleasePool alloc] init]; } diff --git a/gdk/quartz/gdkwindow-quartz.h b/gdk/quartz/gdkwindow-quartz.h index 090c0cca0f..b3e3fb9db2 100644 --- a/gdk/quartz/gdkwindow-quartz.h +++ b/gdk/quartz/gdkwindow-quartz.h @@ -54,11 +54,6 @@ struct _GdkWindowImplQuartz GdkWindowTypeHint type_hint; - /* This is the autorelease pool which is retained - * while the context is being held - */ - NSAutoreleasePool *pool; - NSCursor *nscursor; GdkRegion *paint_clip_region;