From dc5bc71418769264cac97c5aa0688fa118b4764d Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sat, 5 Jan 2008 14:40:05 -0800 Subject: [PATCH] Use garbage collection and add -[SocketWrapper close] to close down the socket and not do it in -[finalize] --- MacGDBp.xcodeproj/project.pbxproj | 1 + Source/ConnectWindowController.m | 16 +--------------- Source/DebuggerConnection.h | 2 ++ Source/DebuggerConnection.m | 20 ++++---------------- Source/DebuggerWindowController.m | 14 +++----------- Source/SocketWrapper.h | 1 + Source/SocketWrapper.m | 8 +------- 7 files changed, 13 insertions(+), 49 deletions(-) diff --git a/MacGDBp.xcodeproj/project.pbxproj b/MacGDBp.xcodeproj/project.pbxproj index b520caa..668bf73 100644 --- a/MacGDBp.xcodeproj/project.pbxproj +++ b/MacGDBp.xcodeproj/project.pbxproj @@ -311,6 +311,7 @@ isa = XCBuildConfiguration; buildSettings = { GCC_C_LANGUAGE_STANDARD = c99; + GCC_ENABLE_OBJC_GC = required; GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNUSED_VARIABLE = YES; PREBINDING = NO; diff --git a/Source/ConnectWindowController.m b/Source/ConnectWindowController.m index f9e7dff..19cce04 100644 --- a/Source/ConnectWindowController.m +++ b/Source/ConnectWindowController.m @@ -30,30 +30,16 @@ { instance = [[ConnectWindowController alloc] initWithWindowNibName:@"Connect"]; [instance window]; - - [[NSNotificationCenter defaultCenter] addObserver:instance - selector:@selector(applicationWillTerminate:) - name:NSApplicationWillTerminateNotification - object:NSApp]; - } return instance; } -/** - * Called when the applicaion is about to terminate so we can release itself - */ -- (void)applicationWillTerminate:(NSNotification *)notif -{ - [self release]; -} - /** * Creates a new DebuggerConnection object (and then completely forgets about it) and then close the window */ - (IBAction)connect:(id)sender { - [[[DebuggerWindowController alloc] initWithPort:[port intValue] session:[session stringValue]] release]; + [[DebuggerWindowController alloc] initWithPort:[port intValue] session:[session stringValue]]; [[self window] orderOut:self]; } diff --git a/Source/DebuggerConnection.h b/Source/DebuggerConnection.h index 3e5ad46..78baced 100644 --- a/Source/DebuggerConnection.h +++ b/Source/DebuggerConnection.h @@ -31,6 +31,8 @@ id depthFetchNode; } +@property(readonly) SocketWrapper *socket; + // initializer - (id)initWithWindowController:(DebuggerWindowController *)wc port:(int)aPort session:(NSString *)aSession; diff --git a/Source/DebuggerConnection.m b/Source/DebuggerConnection.m index d267860..d264835 100644 --- a/Source/DebuggerConnection.m +++ b/Source/DebuggerConnection.m @@ -25,6 +25,8 @@ @implementation DebuggerConnection +@synthesize socket; + /** * Creates a new DebuggerConnection and initializes the socket from the given connection * paramters. @@ -34,10 +36,10 @@ if (self = [super init]) { port = aPort; - session = [aSession retain]; + session = aSession; connected = NO; - windowController = [wc retain]; + windowController = wc; // now that we have our host information, open the socket socket = [[SocketWrapper alloc] initWithPort:port]; @@ -47,18 +49,6 @@ return self; } -/** - * Releases all of the object's data members and closes the streams - */ -- (void)dealloc -{ - [session release]; - [socket release]; - [windowController release]; - - [super dealloc]; -} - /** * Gets the port number */ @@ -115,8 +105,6 @@ { [self performSelector:selector withObject:doc]; } - - [doc release]; } /** diff --git a/Source/DebuggerWindowController.m b/Source/DebuggerWindowController.m index 436af60..e443136 100644 --- a/Source/DebuggerWindowController.m +++ b/Source/DebuggerWindowController.m @@ -58,13 +58,11 @@ } /** - * Release object members + * Called right before the window closes so that we can tell the socket to close down */ -- (void)dealloc +- (void)windowWillClose:(NSNotification *)notif { - [expandedRegisters release]; - - [super dealloc]; + [[connection socket] close]; } /** @@ -111,13 +109,7 @@ */ - (void)setStack:(NSArray *)node { - if (stack != nil) - { - [stack release]; - } - stack = node; - [stack retain]; if ([stack count] > 1) { diff --git a/Source/SocketWrapper.h b/Source/SocketWrapper.h index 639a793..9e58d48 100644 --- a/Source/SocketWrapper.h +++ b/Source/SocketWrapper.h @@ -30,6 +30,7 @@ - (void)setDelegate:(id)aDelegate; - (void)connect; +- (void)close; - (void)receive:(SEL)selector; - (void)send:(NSString *)data; diff --git a/Source/SocketWrapper.m b/Source/SocketWrapper.m index 4e1f1f9..d0c0d64 100644 --- a/Source/SocketWrapper.m +++ b/Source/SocketWrapper.m @@ -58,12 +58,10 @@ NSString *NsockDataSent = @"SocketWrapper_DataSent"; /** * Close our socket and clean up anything else */ -- (void)dealloc +- (void)close { [[NSNotificationCenter defaultCenter] removeObserver:self]; close(sock); - - [super dealloc]; } /** @@ -148,8 +146,6 @@ NSString *NsockDataSent = @"SocketWrapper_DataSent"; */ - (void)connect:(id)obj { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - // create an INET socket that we'll be listen()ing on int socketOpen = socket(PF_INET, SOCK_STREAM, 0); @@ -200,8 +196,6 @@ NSString *NsockDataSent = @"SocketWrapper_DataSent"; close(socketOpen); [self postNotification:NsockDidAccept withObject:nil]; - - [pool release]; } /** -- 2.22.5