Fixed Objective-C memory leaks
authorSam Lantinga <slouken@libsdl.org>
Tue, 25 Jul 2006 06:59:14 +0000
changeset 193705e88d266921
parent 1936 83946ee0ff1f
child 1938 861893943d53
Fixed Objective-C memory leaks
Send an SDL quit event when Command-Q is pressed.
src/video/cocoa/SDL_cocoaevents.m
src/video/cocoa/SDL_cocoawindow.m
     1.1 --- a/src/video/cocoa/SDL_cocoaevents.m	Tue Jul 25 06:22:42 2006 +0000
     1.2 +++ b/src/video/cocoa/SDL_cocoaevents.m	Tue Jul 25 06:59:14 2006 +0000
     1.3 @@ -37,6 +37,18 @@
     1.4  }
     1.5  @end
     1.6  
     1.7 +@interface SDLAppDelegate : NSObject
     1.8 +- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender;
     1.9 +@end
    1.10 +
    1.11 +@implementation SDLAppDelegate : NSObject
    1.12 +- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
    1.13 +{
    1.14 +    SDL_SendQuit();
    1.15 +    return NSTerminateCancel;
    1.16 +}
    1.17 +@end
    1.18 +
    1.19  static NSString *
    1.20  GetApplicationName(void)
    1.21  {
    1.22 @@ -139,6 +151,9 @@
    1.23          }
    1.24          [NSApp finishLaunching];
    1.25      }
    1.26 +    if ([NSApp delegate] == nil) {
    1.27 +        [NSApp setDelegate:[[SDLAppDelegate alloc] init]];
    1.28 +    }
    1.29      [NSApp setRunning];
    1.30      [pool release];
    1.31  }
     2.1 --- a/src/video/cocoa/SDL_cocoawindow.m	Tue Jul 25 06:22:42 2006 +0000
     2.2 +++ b/src/video/cocoa/SDL_cocoawindow.m	Tue Jul 25 06:59:14 2006 +0000
     2.3 @@ -419,6 +419,7 @@
     2.4  void
     2.5  Cocoa_SetWindowTitle(_THIS, SDL_Window * window)
     2.6  {
     2.7 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
     2.8      NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->window;
     2.9      NSString *string;
    2.10  
    2.11 @@ -426,11 +427,13 @@
    2.12      [nswindow setTitle:string];
    2.13      [nswindow setMiniwindowTitle:string];
    2.14      [string release];
    2.15 +    [pool release];
    2.16  }
    2.17  
    2.18  void
    2.19  Cocoa_SetWindowPosition(_THIS, SDL_Window * window)
    2.20  {
    2.21 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    2.22      NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->window;
    2.23      NSRect rect;
    2.24  
    2.25 @@ -441,25 +444,30 @@
    2.26      ConvertNSRect(&rect);
    2.27      rect = [nswindow frameRectForContentRect:rect];
    2.28      [nswindow setFrameOrigin:rect.origin];
    2.29 +    [pool release];
    2.30  }
    2.31  
    2.32  void
    2.33  Cocoa_SetWindowSize(_THIS, SDL_Window * window)
    2.34  {
    2.35 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    2.36      NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->window;
    2.37      NSSize size;
    2.38  
    2.39      size.width = window->w;
    2.40      size.height = window->h;
    2.41      [nswindow setContentSize:size];
    2.42 +    [pool release];
    2.43  }
    2.44  
    2.45  void
    2.46  Cocoa_ShowWindow(_THIS, SDL_Window * window)
    2.47  {
    2.48 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    2.49      NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->window;
    2.50  
    2.51      [nswindow makeKeyAndOrderFront:nil];
    2.52 +    [pool release];
    2.53  }
    2.54  
    2.55  void
    2.56 @@ -473,25 +481,31 @@
    2.57  void
    2.58  Cocoa_RaiseWindow(_THIS, SDL_Window * window)
    2.59  {
    2.60 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    2.61      NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->window;
    2.62  
    2.63      [nswindow makeKeyAndOrderFront:nil];
    2.64 +    [pool release];
    2.65  }
    2.66  
    2.67  void
    2.68  Cocoa_MaximizeWindow(_THIS, SDL_Window * window)
    2.69  {
    2.70 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    2.71      NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->window;
    2.72  
    2.73      [nswindow performZoom:nil];
    2.74 +    [pool release];
    2.75  }
    2.76  
    2.77  void
    2.78  Cocoa_MinimizeWindow(_THIS, SDL_Window * window)
    2.79  {
    2.80 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    2.81      NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->window;
    2.82  
    2.83      [nswindow performMiniaturize:nil];
    2.84 +    [pool release];
    2.85  }
    2.86  
    2.87  void
    2.88 @@ -516,24 +530,23 @@
    2.89  void
    2.90  Cocoa_DestroyWindow(_THIS, SDL_Window * window)
    2.91  {
    2.92 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    2.93      SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
    2.94  
    2.95      if (data) {
    2.96 -        NSAutoreleasePool *pool;
    2.97  #ifdef SDL_VIDEO_OPENGL
    2.98          if (window->flags & SDL_WINDOW_OPENGL) {
    2.99              Cocoa_GL_CleanupWindow(_this, window);
   2.100          }
   2.101  #endif
   2.102 -        pool = [[NSAutoreleasePool alloc] init];
   2.103          [data->listener close];
   2.104          [data->listener release];
   2.105          if (data->created) {
   2.106              [data->window close];
   2.107          }
   2.108          SDL_free(data);
   2.109 -        [pool release];
   2.110      }
   2.111 +    [pool release];
   2.112  }
   2.113  
   2.114  SDL_bool